洛谷 P1969 积木大赛 —— 水题

题目:https://www.luogu.org/problemnew/show/P1969

看每个高度和前面的关系即可。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const maxn=1e5+5;
int n,ans;
int main()
{
  scanf("%d",&n);
  for(int i=1,h,pre;i<=n;i++)
    {
      scanf("%d",&h);
      if(i==1)ans=h;
      else if(h>pre)ans+=h-pre;
      pre=h;
    }
  printf("%d
",ans);
  return 0;
}
原文地址:https://www.cnblogs.com/Zinn/p/9648018.html