ZOJ 3876 May Day Holiday

題意:每年的5月1日-5日是固定休假,並且如果有雙休日與之相鄰,則加上雙休日的時間。求n年的51節連續放幾天假

鏈接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5524

思路:模擬,求出每個5月1日是星期幾

注意點:無


以下爲AC代碼:

Run ID Submit Time Judge Status Problem ID Language Run Time(ms) Run Memory(KB) User Name
3946188 2015-04-27 17:34:15 Accepted 3876 C++0x 0 320 luminus
/* 
***********************************************
*# @Author  : Luminous11 ([email protected])
*# @Date    : 2015-04-27 17:19:20
*# @Link    : http://blog.csdn.net/luminous11
*********************************************** 
*/

#include <bits/stdc++.h>
#define clr(a, v) memset( a , v , sizeof(a) )
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1.0);
bool y[10005];
int ans[10005];
int main()
{
	ios::sync_with_stdio ( false );
	for ( int i = 0; i < 10005; i ++ ){
		if ( ( i % 4 == 0 && i % 100 != 0 ) || ( i % 400 == 0 ) ){
			y[i] = 1;
		}
		else{
			y[i] = 0;
		}
	}
	ans[1928] = 2;
	for ( int i = 1929; i < 10005; i ++ ){
		ans[i] = ( ans[i-1] + 365 + y[i] ) % 7;
	}
	for ( int i = 0; i < 10005; i ++ ){
		if ( ans[i] == 0 )ans[i] = 6;
		else if ( ans[i] == 1 )ans[i] = 9;
		else if ( ans[i] == 2 )ans[i] = 6;
		else if ( ans[i] == 3 )ans[i] = 5;
		else if ( ans[i] == 4 )ans[i] = 5;
		else if ( ans[i] == 5 )ans[i] = 5;
		else if ( ans[i] == 6 )ans[i] = 5;
	}
	int T;
	scanf ( "%d", &T );
	while ( T -- ){
		int n;
		scanf ( "%d", &n );
		printf ( "%d\n", ans[n] );	
	}
    return 0;
}


發佈了228 篇原創文章 · 獲贊 5 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章