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


hdu 1076 An Easy Task

    好久都沒寫題了,完全不會,這麼簡單的題WA了近10次,最後發現是思路不完全。

   最近要抓緊訓練了,不然就坐等被虐了,明天開始學習dp


/*
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;
bool isleap(int a)
{
    return a%4==0 && (a%100!=0||a%400==0);
}
int main()
{
    int T;
    scanf("%d",&T);
    int now,n;
    while(T--)
    {
        scanf("%d%d",&now,&n);
        if(!isleap(now))
        {
            now=(((now/4)+1)*4);
            if(!isleap(now))now+=4;
        }
        n--;
        while(n>=97)
        {
            n-=97;now+=400;
        }
        while(n>24)
        {
            int t=now/100;
            n-=24;now+=100;
            if(now/100>t&&(now/100)%4==0)n--;
        }
        int t=now%100;
        now+=n*4;
        if(n&&t>=now%100&&(now/100)%4!=0)now+=4;
        printf("%d\n",now);
    }
}


最後更新:2017-04-03 21:30:11

  上一篇:go 解密Facebook產品的開發流程
  下一篇:go JAVA中的內存溢出