HDU-------An Easy Task

An Easy Task

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4088 Accepted Submission(s): 2327
 

Problem Description

Ignatius was born in a leap year, so he want to know when he could hold his birthday party. Can you tell him?

Given a positive
integers Y which indicate the start year, and a positive integer N, your task is
to tell the Nth leap year from year Y.

Note: if year Y is a leap year,
then the 1st leap year is year Y.


Input

The input contains several test cases. The first line
of the input is a single integer T which is the number of test cases. T test
cases follow.
Each test case contains two positive integers Y and
N(1<=N<=10000).


Output

For each test case, you should output the Nth leap year
from year Y.


Sample Input

3
2005 25
1855 12
2004 10000


Sample Output

2108
1904
43236

Hint

We call year Y a leap year only if (Y%4==0 && Y%100!=0) or Y%400==0.


Author

Ignatius.L

easy task并不easy 无奈 不过不着急慢慢来 在错误和失败中学到东西才是重要的

上代码

 1 #include <iostream>
 2 using namespace std;
 3 //int leapJudge(int);
 4 int main(){
 5     int cont,sYear,pYear;
 6
 7     cin>>cont;
 8     //while(cont--)//这个cont--还是谜一样的存在 !while(i--)中i是有个初值的,每次循环i会减1,当i的值等于0的时候,循环就会终止!
 9
10     for(int i =0;i<cont;i++)
11     {
12         int sYear = 0;
13         int pYear = 0;
14         cin>>sYear>>pYear;
15         int leapcont = 0;  //!!!!!!重大错误就出现在这句 之前把他放在第一层循环外 也是脑子瓦特掉了
16             int j;
17             for(j=sYear;;j++){
18                 if(leapcont==pYear) break;
19                 if((j%4==0&&j%100!=0)|j%400==0)//去掉了判断函数 因为确实是没什么卵用
20                      leapcont++;
21             }
22         cout<<j-1<<endl;//此处也是有一个错误 应该输出j-1
23     }
24     //system("pause");
25     return 0;
26 }
27 //int leapJudge(int Y){
28 //     if( (Y%4==0 && Y%100!=0)||Y%400==0)
29 //    return 1;
30 //}
31
32 //#include<iostream>
33 //using namespace std;
34 //
35 //int main()
36 //{
37 //    int cases;//
38 //    int k;
39 //    cin>>cases;
40 //    while(cases--)
41 //    {
42 //        int y,n;
43 //        cin>>y>>n;
44 //        int num=0;
45 //        for(k=y;;k++)
46 //        {
47 //            if(num==n) break;
48 //            //判断是不是闰年
49 //            if(k%4==0 && k%100!=0 || k%400==0)
50 //                num++;
51 //        }
52 //        cout<<k-1<<endl;
53 //    }
54 //    system("pause");
55 //    return 0;
56 //}

总结:循环之间的逻辑不清晰

时间: 2025-01-13 04:23:59

HDU-------An Easy Task的相关文章

杭电OJ(HDU)-ACMSteps-Chapter Two-《An Easy Task》《Buildings》《decimal system》《Vowel Counting》

http://acm.hdu.edu.cn/game/entry/problem/list.php?chapterid=1§ionid=2 1.2.5 #include<stdio.h> /* 题意:找闰年. if((i%4==0 && i%100!=0) || i%400==0)count++; 3 2005 25 1855 12 2004 10000 2108 1904 43236 */ int main() { int t,y,n; int i,count=0; whil

哈理工2015暑假训练赛BNU16488 Easy Task(简单题)

A - Easy Task Time Limit:2000MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatusPracticeZOJ 2969 Description Calculating the derivation of a polynomial is an easy task. Given a function f(x) , we use (f(x))' to denote its derivatio

HDU 4907 BestCoder3_1 Task schedule

Task schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description 有一台机器,并且给你这台机器的工作表,工作表上有n个任务,机器在ti时间执行第i个任务,1秒即可完成1个任务.有m个询问,每个询问有一个数字q,表示如果在q时间

hdu 1885 Key Task (三维bfs)

题目 之前比赛的一个题, 当时是崔老师做的,今天我自己做了一下.... 还要注意用bfs的时候  有时候并不是最先到达的就是答案,比如HDU 3442 这道题是要求最小的消耗血量伤害,但是并不是最先到达目标点的路径 就是最小的伤害,因为每一个点的伤害是 不一样的, 这种情况要用优先队列优化, 对伤害优化. 题意:*开始, X出口, b, y, r, g 代表钥匙,分别可以开B, Y, R, G颜色的门, 钥匙可以多次使用.问最短的步骤. 思路:vis[][][]数组开三维,第三维记录状态 是否拿

HDU-1076-An Easy Task(Debian下水题测试.....)

An Easy Task Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17062    Accepted Submission(s): 10902 Problem Description Ignatius was born in a leap year, so he want to know when he could hold h

[ACM] ZOJ 3844 Easy Task (模拟+哈希)

Easy Task Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these n integers. And then you should replace both a and bwith a-b. Yo

ZOJ 2969: Easy Task

ZOJ 2969: Easy Task 1 ///@date 2017-02-07 2 ///@author Sycamore, ZJNU 3 #include <iostream> 4 using namespace std; 5 int c[1001]; 6 int main() 7 { 8 int T; 9 cin >> T; 10 while (T--) 11 { 12 int N; 13 cin >> N; 14 for (int i = N; i >=

二分+DP HDU 3433 A Task Process

HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1368    Accepted Submission(s): 684 Problem Description There are two kinds of tasks, namely A and B. There are N workers

2016 省热身赛 Easy Task

Easy Task Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description You are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these nintegers. And then you sho