机器人跳跃问题

https://www.nowcoder.com/exam/test/65717435/detail?pid=16516564&examPageSource=Company&testCallback=https%3A%2F%2Fwww.nowcoder.com%2Fexam%2Fcompany%3FcurrentTab%3Drecommand%26jobId%3D100%26selectStatus%3D0%26tagIds%3D665&testclass=%E8%BD%AF%E4%BB%B6%E5%BC%80%E5%8F%91

找规律,发现每次跳跃到下一阶段,能量都会变为:2*E-H(k+1)

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N;
    cin>>N;
    vector<int> H(N+1,0);
    int i = 1;
    while (cin >> H[i++]) { // 注意 while 处理多个 case
    }
    long long res = 0;
    for(i= N;i>0;i--){
        res = res + H[i];
        res = (res + 1) / 2;
    }
    cout<<res<<'\n';
    return 0;
}
// 64 位输出请用 printf("%lld")

 

posted @   重新出发123  阅读(62)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示