当前位置:网站首页>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;
}
边栏推荐
- System Verilog - thread
- Go closure usage example
- p1408
- Common dynamic memory errors
- Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
- Gif动图如何裁剪?收下这个图片在线裁剪工具
- JS Base64 Library Learning
- System Verilog - function and task
- Remove interval (greedy)
- Add the resources directory under test in idea
猜你喜欢
One question per day,
Iterator failure condition
System Verilog - thread
[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination
Kubernetes understands kubectl/ debugging
Sequential programming 1
Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat
弹性布局(display:flex;)属性详解
Ubuntu 20.04 installing mysql8.0 and modifying the MySQL password
从0到1完全掌握 XSS
随机推荐
从0到1完全掌握 XSS
Std:: vector minutes
QT opens the print dialog box in a text editor
电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
What is the safest app for stock account opening? Tell me what you know
移除区间(贪心)
Explanation of dev/mapper
Gif动图如何裁剪?收下这个图片在线裁剪工具
C language escape character and its meaning
Brain tree (I)
Is it normal to dig for money? Is it safe to open a stock account?
Uniapp icon configuration
Add the resources directory under test in idea
Function of getinstance() method
Judging the number of leap years from 1 to N years
QT loading third-party library basic operation
Is it safe to open an online stock account? Who knows
分饼干问题
‘make_ unique’ is not a member of ‘std’
[HBZ sharing] use of locksupport