当前位置:网站首页>The robot is playing an old DOS based game
The robot is playing an old DOS based game
2022-06-25 14:58:00 【qq_ twenty-three million nine hundred and fifty-three thousand 】
Robots are playing an ancient game based on DOS The game of . There is... In the game N+1 building —— from 0 To N Number , From left to right . The number is 0 The height of the building is 0 A unit of , The number is i The height of the building is H(i) A unit of .
At first , The robot is numbered 0 At the building . Each step , It jumps to the next ( On the right ) Architecture . Suppose the robot is in the k A building , And its current energy value is E, Next, it will jump to the k+1 Architecture . It will gain or lose in proportion to H(k+1) And E Energy of difference . If H(k+1) > E Then the robot will lose H(k+1) - E Energy value of , Otherwise it will get E - H(k+1) Energy value of .
The goal of the game is to reach the third N Architecture , In the process , Energy value cannot be negative units . The question now is how much energy the robot starts the game , To ensure the successful completion of the game ?
analysis :
1, If E > H(k + 1) be E = E + (E - H(k + 1))
2, If E < H(k + 1) be E = E - (H(K + 1) - E)
in summary ,E = 2*E - H(K + 1)
The above backward method can be used to solve the problem
#include
#include
using namespace std;
int main()
{
int iNum;
cin >> iNum;
std::vector v;
for(int i = 0; i <iNum; i++)
{
int iTmp;
cin >> iTmp;
v.push_back(iTmp);
}
int iE = 0;
int iTmp = 0;
for(int j = iNum - 1; j >= 0 ; j--)
{
iTmp = iE +v[j];
if(iTmp & 0x1)
iTmp += 1;
iE = iTmp / 2;
}
cout <<iE;
return 0;
}
边栏推荐
- 15 -- 最接近原点的 K 个点
- Kubernetes understands kubectl/ debugging
- Jaspersoft studio adding MySQL database configuration
- Uniapp icon configuration
- (translation) json-rpc 2.0 specification (Chinese version)
- ffmpeg protocol concat 进行ts流合并视频的时间戳计算及其音画同步方式一点浅析
- Sequential programming 1
- QT file reading -qfile
- Study notes of cmake
- 2. operator and expression multiple choice questions
猜你喜欢

‘make_ unique’ is not a member of ‘std’

System Verilog — interface

What moment makes you think there is a bug in the world?

Learning notes on February 5, 2022 (C language)

How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps
![[try to hack] vulhub shooting range construction](/img/fc/6057b6dec9b51894140453e5422176.png)
[try to hack] vulhub shooting range construction

New good friend Pinia, leading the new era of state management

Jaspersoft studio adding MySQL database configuration

Std:: vector minutes

JS select all exercise
随机推荐
NBD Network Block Device
Application of TSDB in civil aircraft industry
New good friend Pinia, leading the new era of state management
[Ocean University of China] Data Sharing for retest of initial Examination
关于win10 版本kicad 卡死的问题, 版本6.x
[untitled] PTA check password
【中国海洋大学】考研初试复试资料分享
从408改考自主命题,211贵州大学考研改考
[deep learning] multi label learning
Biscuit distribution
QT file reading -qfile
Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
System Verilog - function and task
Usage of qlist
JS determines whether two values are equal, and compares any two values, including array objects
How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps
In 2022, the score line of Guangdong college entrance examination was released, and several families were happy and several worried
3. Sequential structure multiple choice questions
ffmpeg protocol concat 进行ts流合并视频的时间戳计算及其音画同步方式一点浅析
Common dynamic memory errors