您的位置:首页 > 产品设计 > UI/UE

UESTC 1817 Complete Building the Houses 贪心

2013-05-03 00:27 190 查看
同是比赛时候的一道水题,比赛的时候以为满层的就不能继续建了,没想到可以忽视它……

搞清题意后,唯一要注意的一点就是ans是long long的

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#define INF 1E9
using namespace std;
int a[1000001];
long long ans=0;
int main()
{
int now;
int T,C=0;
int n,m,i,t;
scanf("%d",&T);
while(T--)
{
ans=now=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&t);
if(now>=t)
a[i]=0;
else
{
a[i]=t-now;
ans+=a[i];
now=t;
}
if(i+1-m>=0)//超过m长度
now-=a[i+1-m];
}
printf("Case #%d: %lld\n",++C,ans);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: