閱讀592 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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

  上一篇:go apache + tomcat + oracle + opencms 備忘
  下一篇:go MFC VS2012對話框背景填圖