hdu 1076 An Easy Task (水题)

来源:互联网 发布:紫光存储芯片 知乎 编辑:程序博客网 时间:2024/06/05 20:20

思路:从第一个闰年开始,年份一直加4的算,算到第n个闰年。输出年份即可。


代码:

#include <iostream>#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <map>#include <set>#include <vector>#include <algorithm>using namespace std;#define mst(a,b) memset(a,b,sizeof(a))#define eps 10e-8const int MAX_ = 10010;const int MAX = 0x7fffffff;int T, n, y, cnt;bool isleap(int year){    return ((year%4==0&&year%100!=0)||(year%400==0));}int main(){    scanf("%d",&T);    while(T--){        scanf("%d%d",&y,&n);        while(!isleap(y)){            y++;        }        cnt = 1;        while(cnt != n){            y+=4;            if(isleap(y))cnt++;        }        cout<<y<<endl;    }    return 0;}



0 0