题意:每年的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 (573728051@qq.com)
*# @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;
}