hdu 1076 An Easy Task (水题)
2014-04-07 14:12
363 查看
思路:从第一个闰年开始,年份一直加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;
}
代码:
#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;
}
相关文章推荐
- HDU——1076 An easy task(水题)
- hdu 1076 An Easy Task
- hdu 1076 An Easy Task
- hdu 1076 an easy task
- An Easy Task HDU1076
- HDU 1076 An Easy Task (水)
- HDU-1076-An Easy Task(第m个闰年年份)
- hdu 1076 An Easy Task
- hdu-1076-An Easy Task
- HDU 1076 An Easy Task
- HDU 1076 An Easy Task
- HDU 1076 An Easy Task
- Hdu 1076 An Easy Task【水】
- HDU 1076 An Easy Task
- HDU 1076 An Easy Task
- hdu-oj 1076 An Easy Task
- hdu 1076 An Easy Task
- HDU 1076 An Easy Task
- Hdu 1076 - An Easy Task
- 【HDU】1076 An Easy Task