ZOJ 3876 May Day Holiday

12 篇文章 0 订阅

题意:每年的5月1日-5日是固定休假,并且如果有双休日与之相邻,则加上双休日的时间。求n年的51节连续放几天假

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

思路:模拟,求出每个5月1日是星期几

注意点:无


以下为AC代码:

Run IDSubmit TimeJudge StatusProblem IDLanguageRun Time(ms)Run Memory(KB)User Name
39461882015-04-27 17:34:15Accepted 3876C++0x0320luminus
/* 
***********************************************
*# @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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值