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