ZOJ3876 May Day Holiday

来源:互联网 发布:网络用语盘点 编辑:程序博客网 时间:2024/05/21 14:50

             题目大意:求输入年份的那一年的五一劳动节,在Marjar University 的学生能够休息多少天。。。

         题目并不难,只需要我们知道一个小常识:闰年的一年有366天,而判定闰年的前提是能被4整除但不能被100整除、或者能被400整除即为

闰年。那么这样一来实现起来就容易了,以某一年的五一是星期几为基准,我们判定它与输入年份之间相隔多少天,如果时间是往后退那么这

一年五一开始的一天一定等于基准年的星期加上相隔天数再mod(7)就能知道了。反之如果是往前推,那么就用基准年五一开始的星期减去相

隔天数mod(7)便可得出结果。

         实现很快,我还是WA了7次。。。

        光考虑题目说的情况去了,一直以为自己的做题方法有问题。其实再看看题会发现除了题目说的三种情况。星期二也是可以休息6天的。

May Day Holiday

Time Limit: 2 Seconds      Memory Limit: 65536 KB

As a university advocating self-learning and work-rest balance, Marjar University has so many days of rest, including holidays and weekends. Each weekend, which consists of Saturday and Sunday, is a rest time in the Marjar University.

The May Day, also known as International Workers' Day or International Labour Day, falls on May 1st. In Marjar University, the May Day holiday is a five-day vacation from May 1st to May 5th. Due to Saturday or Sunday may be adjacent to the May Day holiday, the continuous vacation may be as long as nine days in reality. For example, the May Day in 2015 is Friday so the continuous vacation is only 5 days (May 1st to May 5th). And the May Day in 2016 is Sunday so the continuous vacation is 6 days (April 30th to May 5th). In 2017, the May Day is Monday so the vacation is 9 days (April 29th to May 7th). How excited!

Edward, the headmaster of Marjar University, is very curious how long is the continuous vacation containing May Day in different years. Can you help him?

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case, there is an integer y (1928 <= y <= 9999) in one line, indicating the year of Edward's query.

Output

For each case, print the number of days of the continuous vacation in that year.

Sample Input

3201520162017

Output

569

#include<iostream>#include<cmath>#include<cstdio>using namespace std;int yy(int n){if((n%4==0&&n%100!=0)||n%400==0)  return 1;else return 0;}void d(int n){if(n==1) printf("9\n");else if(n==0||n==2) printf("6\n");else  printf("5\n");}int main(){int T,year,nowyear,day,sum;year=2015,day=5;cin>>T;while(T--){sum=0;cin>>nowyear;if(nowyear==year) d(day);else if(nowyear>year){for(int i=year+1;i<=nowyear;i++)  {    if(yy(i)) sum+=366;    else sum+=365;  }    int t=(sum+day)%7;    //cout<<t<<endl;d(t);}else if(nowyear<year){for(int i=year;i>nowyear;i--)  {    if(yy(i)) sum+=366;    else sum+=365;  }         // cout<<sum<<"dd"<<endl;  int t=(sum)%7;  t=day-t;  if(t<0)  t+=7;//cout<<t<<endl;d(t);}}return 0;}


0 0