ZOJ 3876 May Day Holiday

题目链接:http://icpc.moe/onlinejudge/showProblem.do?problemId=5524

不知道大家这道题是怎么过的,有些人是找400的周期,有些人根本不找周期直接预处理,但是其实……这个题可以直接根据基姆拉尔森计算公式来计算星期几

基姆拉尔森计算公式:W = (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 

#include <cstdio>
#include <cstring>
int week[7] = {6,9,6,5,5,5,5};
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int y;
		scanf("%d",&y);
		int w = (1+2*5+3*(5+1)+y+y/4-y/100+y/400)%7;
		//printf("%d\n",w);
		printf("%d\n",week[w]);
	}
}


你可能感兴趣的:(ZOJ 3876 May Day Holiday)