洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
来源:互联网 发布:数据库测试方法 编辑:程序博客网 时间:2024/06/05 00:00
题目描述
13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.
这里有一些你要知道的:
1、1900年1月1日是星期一.
2、4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.
3、年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).
4、以上规则不适合于世纪年。可以被400整除的世纪年为闰年,否则为平年。所以,1700,1800,1900和2100年是平年,而2000年是闰年.
请不要调用现成的函数
请不要预先算好数据(就是叫不准打表)!
输入输出格式
输入格式:一个正整数n.
输出格式:输入输出样例
输入样例#1:
20
输出样例#1:
36 33 34 33 35 35 34
说明
题目翻译来自NOCOW。
USACO Training Section 1.1
本来不打算做了,刚学编程时做过一道类似的题,恶心 了我一中午。
哈哈哈,还好题解中有蔡勒公式这种神奇的东西就写了一下,很水。
注意:输出顺序是从周六开始到周五,迷之题目描述。
#include<iostream>#include<cstdio>using namespace std;int n,cnt[11];int zeller(int year,int month,int day){int c,y,m,d,w;m=month,d=day;if(m<=2)year--,m+=12;c=year/100,y=year%100;w=(y+y/4+c/4-2*c+(13*(m+1))/5+d-1)%7;while(w<0)w+=7;return w;}int main(){scanf("%d",&n);for(int i=1900;i<=1900+n-1;i++)for(int j=1;j<=12;j++)cnt[zeller(i,j,13)]++;printf("%d ",cnt[6]);for(int i=0;i<=5;i++)printf("%d ",cnt[i]);printf("\n");return 0;}
0 0
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 【模拟】洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
- luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
- [USACO1.1]黑色星期五Friday the Thirteenth-洛谷 1202
- 【USACO1.1_3】★Friday the Thirteenth 黑色星期五
- usaco1.1.3 Friday the Thirteenth黑色星期五
- USACO1.1.3 Friday the Thirteenth(黑色星期五)
- [USACO1.1]Friday the Thirteenth
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth 黑色星期五
- USACO1.1 Friday the Thirteenth 比较分析
- Friday the Thirteenth(黑色星期五) USACO
- USACO1.1.3[Friday The Thirteenth]
- USACO1.1.3 Friday the Thirteenth
- USACO1.1.3 - Friday the Thirteenth
- USACO1.1.3 Friday the Thirteenth
- xcode不能使用autocomplete的原因之一
- 制作一个简易的网页,用不同的颜色区分头部、内容以及底部,在滚动页面的过程中,底部保持不变。
- linux安装Django1.9
- wait notify 锁机制
- 斐波那契数列-递归初步
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 使用 Docker 搭建 Java Web 运行环境
- 自定义View实现手机qq5.X的抽屉特效和聊天界面联系人左滑功能
- 20161106学习心得
- linux UDP网络编程
- 1057. 数零壹(20)
- Spring各jar包的作用(转载)
- 122. Best Time to Buy and Sell Stock II 类别:贪心算法 难度:medium
- Form表单验证之使用session做交互