CodeFoeces-265B

题目

原题链接:B. Roadside Trees (Simplified Edition)

题意

有n棵树,每棵树高度hi且树顶有果实,每秒可以执行三种操作:
1:向上或下爬一单位;
2:吃掉果实;
3:跳到隔壁的树的相同高度。
初始在第一棵树的树底。问最少需要多少秒。
题意没有理解透彻,模拟可过。

代码

#include
using namespace std;
int main() {
    int n,h[100000];
    cin>>n;
    for(int i=0; i>h[i];
    }
    int ans=0;
    ans+=h[0]+1;
    for(int i=1; ih[i-1]) ans+=h[i]-h[i-1]+2;
        else ans+=h[i-1]-h[i]+2;
    }
    cout<

你可能感兴趣的:(CodeFoeces-265B)