H - May Day Holiday——ZOJ

H - May Day Holiday

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld
& %llu

Submit Status

Description

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

3
2015
2016
2017

Output

5
6
9

主要是计算4月29日是星期几:

#include<stdio.h>
#include<string.h>
#include<math.h>
int t;
int CaculateWeekDay(int y,int m, int d);
int judgeyear(int year);
int judgedate(int year,int mouth,int day);
int main()
{
	long date;
	int year,day,mouth;
	int n,flag=0,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		flag=0;
		scanf("%ld",&date);
		year=date;
		mouth=4;
		day=29;
		t=CaculateWeekDay(year,mouth,day)+1;
		switch(t)
		{
			case 1:
			case 2:
			case 3:
			case 4:
				printf("%d\n",5);
				break;
			case 5:
			case 7:
				printf("%d\n",6);
				break;
			case 6:
				printf("%d\n",9);
				break;
		}
	}
	return 0;
} 

int CaculateWeekDay(int y,int m, int d)
{
    if(m==1||m==2) {
        m+=12;
        y--;
    }
    int iWeek=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
  	return iWeek;
} 

关于计算公式详见:

http://blog.csdn.net/chudongfang2015/article/details/51365866

时间: 2024-11-05 21:55:24

H - May Day Holiday——ZOJ的相关文章

12th浙江省省赛 H May Day Holiday

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 an

浙江省赛2015 H.May Day Holiday

The 12th Zhejiang Provincial Collegiate Programming Contest 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 Sund

2017浙江省赛 H - Binary Tree Restoring ZOJ - 3965

地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3965 题目: iven two depth-first-search (DFS) sequences of a binary tree, can you find a binary tree which satisfies both of the DFS sequences? Recall that a binary tree is a tree in which

ZOJ 3876 May Day Holiday 蔡勒公式

                                               H - May Day Holiday Description 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 o

ZOJ 3203 Light Bulb 三分

最简单的三分题,期末考完先做一道练练手 就是这么一个图,告诉你H h D,问你L最长是多少,假设人到灯的距离是X,那么容易得到 L = H-D/x*(H-h)+D-x,求个导很容易发现是一个关于x 的凸性函数,就可以三分啦 要注意的是三分的时候的精度eps,这题要求得是1e-9才能A,1e-8都WA,真是囧 #include <cstdio> #include <sstream> #include <fstream> #include <cstring> #

[GodLove]Wine93 Tarining Round #4

比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44903#overview 题目来源: 2011 Asia ChengDu Regional Contest Wine93有话说: 爆0, oh-year!   ID Origin Title   13 / 118 Problem A HDU 4111 Alice and Bob 137 / 358 Problem B HDU 4112 Break the Chocolate

水题 ZOJ 3876 May Day Holiday

题目传送门 1 /* 2 水题:已知1928年1月1日是星期日,若是闰年加1,总天数对7取余判断就好了: 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cmath> 8 #include <cstring> 9 #include <string> 10 #include <map> 11 #include

ZOJ 3876 May Day Holiday

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, al

ZOJ 3829 Known Notation (2014牡丹江H题)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5383 Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. I