592
技术社区[云栖]
UESTC 1817 Complete Building the Houses 贪心
同是比赛时候的一道水题,比赛的时候以为满层的就不能继续建了,没想到可以忽视它……
搞清题意后,唯一要注意的一点就是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);
}
}
最后更新:2017-04-03 18:52:06
上一篇:
apache + tomcat + oracle + opencms 备忘
下一篇:
MFC VS2012对话框背景填图
谷歌 2012 年终总结:这一年你又好奇着什么?
云栖智能 舒尔数字音频解决方案惊艳亮相
几种常见的基于Lucene的开源搜索解决方案对比
Actor生命周期理解
office 2007、2010提示错误“此错误通常是由宏安全性设置造成”
SNS网站中怎样获取MSN联系人信息
阿里云大数据利器Maxcompute学习之-假如你使用过hive
kafka - advertised.listeners and listeners
oracle中报ora-01033:oracle initializationg or shutdown in progress错
杭电1004