当前位置:网站首页>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;
}
边栏推荐
- Custom structure type
- [Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination
- Daily question, magic square simulation
- Gif动画怎么在线制作?快试试这款gif在线制作工具
- Go语言Zap库Logger的定制化和封装使用详解
- 【Try to Hack】vulnhub DC1
- Flexible layout (display:flex;) Attribute details
- Js- get the mouse coordinates and follow them
- @Font face fonts only work on their own domain - @font-face fonts only work on their own domain
- QT pop up open file dialog box QFileDialog
猜你喜欢

Application of TSDB in civil aircraft industry

有哪个瞬间让你觉得这个世界出bug了?

QQ情话糖果情话内容获取并保存

【中國海洋大學】考研初試複試資料分享
![[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination

QT loading third-party library basic operation

Uniapp icon configuration

Dynamic memory allocation

Open a restaurant

【Try to Hack】vulhub靶场搭建
随机推荐
Biscuit distribution
Golang channel reading data
【深度学习】多标签学习
How to view the Chrome browser plug-in location
Daily question, magic square simulation
System Verilog — interface
How to cut the size of a moving picture? Try this online photo cropping tool
Customization and encapsulation of go language zap library logger
[deep learning] multi task learning of multiple datasets data sets missing labels
【中国海洋大学】考研初试复试资料分享
多张动图怎样合成一张gif?仅需三步快速生成gif动画图片
分饼干问题
Is it normal to dig for money? Is it safe to open a stock account?
SPARQL learning notes of query, an rrdf query language
New good friend Pinia, leading the new era of state management
How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps
Go语言Zap库Logger的定制化和封装使用详解
网上股票开户安不安全?有谁知道呢
C language LNK2019 unresolved external symbols_ Main error
QT file reading -qfile