阅读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中的内存溢出