现在的位置: 首页 > 综合 > 正文

hdu 1076 An Easy Task (水题)

2017年11月23日 ⁄ 综合 ⁄ 共 528字 ⁄ 字号 评论关闭

思路:从第一个闰年开始,年份一直加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-8

const 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;
}

抱歉!评论已关闭.