Friday the Thirteenth(黑色星期五) USACO
来源:互联网 发布:css js 格式化工具 编辑:程序博客网 时间:2024/05/05 20:15
原文地址
Is Friday the 13th really an unusual event?
That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is positive and will not exceed 400.
Note that the start year is NINETEEN HUNDRED, not 1990.
There are few facts you need to know before you can solve this problem:
- January 1, 1900 was on a Monday.
- Thirty days has September, April, June, and November, all the rest have 31 except for February which has 28 except in leap years when it has 29.
- Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year)
- The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year.
Do not use any built-in date functions in your computer language.
Don't just precompute the answers, either, please.
PROGRAM NAME: friday
INPUT FORMAT
One line with the integer N.SAMPLE INPUT (file friday.in)
20
OUTPUT FORMAT
Seven space separated integers on one line. These integers represent the number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, ..., Friday.SAMPLE OUTPUT (file friday.out)
36 33 34 33 35 35 34
/*ID: liuming9LANG: C++TASK: friday*//**ACM入门题目*我因为把1900看成了1990导致我反复检查了好久*/#include <cstdio>int daysofmonth[13][2] = {{0, 0},{31, 31},{28, 29},{31, 31},{30, 30},{31, 31},{30, 30},{31, 31},{31, 31},{30, 30},{31, 31},{30, 30},{31, 31}};bool isYear(int x){return ((x % 400 == 0) || (x % 4 == 0 && x % 100 != 0));}int main(){int n, days, d[8];freopen("friday.in", "r", stdin);freopen("friday.out", "w", stdout);scanf("%d", &n);days = 0;for(int i = 1; i <= 7; i++)d[i] = 0;for(int i = 0; i < n; i++){int t = isYear(1900 + i);for(int j = 1; j <= 12; j++){d[(days + 12) % 7 + 1]++;days += daysofmonth[j][t];}}printf("%d %d %d %d %d %d %d\n", d[6], d[7], d[1], d[2], d[3], d[4], d[5]);return 0;}
- Friday the Thirteenth(黑色星期五) USACO
- USACO——Friday the Thirteenth 黑色星期五
- (usaco) Friday the Thirteenth 黑色星期五
- USACO 1.1 黑色星期五Friday the Thirteenth
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth黑色星期五
- Friday the Thirteenth 黑色星期五
- Usaco 1.1.3 黑色星期五(Friday the Thirteenth)
- 【USACO题库】1.1.3 Friday the Thirteenth黑色星期五
- 【USACO题库】1.1.3 Friday the Thirteenth黑色星期五
- Friday the Thirteenth(USACO)
- usaco--Friday the Thirteenth
- [USACO] Friday the Thirteenth
- usaco Friday the Thirteenth
- USACO Friday the Thirteenth
- USACO:Friday the Thirteenth
- USACO -Friday the Thirteenth
- USACO Friday the Thirteenth
- TabHost
- Opencv的RGB到HSV颜色空间转换
- 静态函数于时间类
- IntelliJ IDEA 12新特性:为Android开发者提供新的XML重构工具
- Ubuntu开机停止在checking battery state页面 解决方法
- Friday the Thirteenth(黑色星期五) USACO
- date函数(百度百科)
- android开发(21)蜂鸣提示音和震动提示的实现。
- Block的内存管理
- 圣经 出埃及记 十诫
- 编译原理
- android 制作的精美闹钟
- ural1297——Palindrome(后缀数组)
- wifi详解(二)