您的位置:首页 > 其它

|洛谷|NOIP2013|贪心|P1969 积木大赛

2016-10-04 15:31 260 查看
http://www.luogu.org/problem/show?pid=1969

如果当前积木高度大于前面的积木高度,说明这块积木要比前面那块积木多操作高出的高度次,而小于等于前面的积木高度,则可以在前面的操作中达到标准

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
int main()
{
int n;
int x1=0, x2=0;
int ans = 0;
scanf("%d", &n);
for (int i=1;i<=n;i++)
{
scanf("%d", &x1);
if (x1>x2) ans += x1-x2;
x2 = x1;
}
printf("%d\n", ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: