1.1.5 PROB Friday the Thirteenth

Friday the Thirteenth

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

===========================================

一看题目的时候,以为让我统计1900~1900+n-1中,星期一~星期天有多少天。

然后码完了才发现。。。是统计13号这一天,我也是醉了

处理策略相当简单,下面是AC代码

 1 /*
 2 ID: luopengting
 3 PROG: friday
 4 LANG: C++
 5 */
 6 #include <iostream>
 7 #include <cstdio>
 8 #include <cstring>
 9 using namespace std;
10 const int maxn = 405;
11 int year[maxn];
12 int days[8];
13 int m[] = {31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30};  //记得12月份摆在第一
14         // 12, 1 , 2,  3,  4,  5,  6,  7,  8,  9,  10, 11
15 int tt;
16 void init()
17 {
18     for(int i = 1900; i < 1900 + maxn; i++)
19     {
20         if((i % 400 == 0) || ((i % 100) && (i % 4 == 0)))
21         {
22             year[i - 1900] = 1;
23         }
24         else
25         {
26             year[i - 1900] = 0;
27         }
28     }
29 }
30 void deal(int n)
31 {
32     tt = - 31;
33     for(int i = 0; i < n; i++)
34     {
35         for(int j = 0; j < 12; j++)
36         {
37             tt += m[j];
38             if(year[i] && j == 2)//闰年
39             {
40                 tt++;
41             }
42             tt %= 7;
43             days[tt]++;
44         }
45     }
46 }
47 int main()
48 {
49     freopen("friday.in","r",stdin);
50     freopen("friday.out","w",stdout);
51     init();
52     int n;
53     while(cin >> n)
54     {
55         memset(days, 0, sizeof(days));
56         deal(n);
57         int i;
58         for(i = 0; i < 6; i++)
59         {
60             cout << days[i] << " ";
61         }
62         cout << days[i] << endl;
63     }
64     return 0;
65 }
时间: 2024-10-14 18:42:11

1.1.5 PROB Friday the Thirteenth的相关文章

USACO Chapter 1 Section 1.1

USACO的题解和翻译已经很多了... 我只是把自己刷的代码保存一下. 1.PROB Your Ride Is Here 1 /* 2 ID:xiekeyi1 3 PROG:ride 4 LANG:C++ 5 */ 6 7 #include<bits/stdc++.h> 8 using namespace std ; 9 10 int main() 11 { 12 freopen("ride.in","r",stdin); 13 freopen(&quo

SDUT 1941-Friday the Thirteenth(水)

Friday the Thirteenth Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 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, w

NOIP 2011 Day 1 部分题解 (Prob#1 and Prob#2)

Problem 1: 铺地毯 乍一看吓cry,地毯覆盖...好像是2-dims 线段树,刚开头就这么难,再一看,只要求求出一个点,果断水题,模拟即可.(注意从标号大的往小的枚举,只要有一块地毯符合要求就输出,返回.) (全篇未完结,代码就不发了.) Problem 2: 选择客栈 模拟果断会超时,所以用类似动态规划的方法. 用$\text{sum}\left[ i\right]$表示从一号客栈到i号客栈途中的符合要求的Café总数,自然,$\text{O}\left( n\right)$的时间复

Friday the Thirteenth

题解: 模拟. 从1990~1990+n-1年之内,每一个月13号是星期几,累计一下就行了(注意:他是从六.日.一.二.三.四.五). { ID:h1956701 LANG:PASCAL PROB:friday } var n,s,i,j:longint; day:array[1..12]of longint=(31,0,31,30,31,30,31,31,30,31,30,31); a:array[0..11]of longint; begin assign(input,'friday.in'

USACO Section 1.1-3 Friday the Thirteenth

Friday the Thirteenth 黑色星期五 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数. 给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400. 注意,开始今年是一千九百年,不是1990 这里有一些你要知道的: 1.1900年1月1日是星期一. 2.4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,

【USACO1.1.3】Friday the Thirteenth

Friday the Thirteenth 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 13t

USACO 1.1 Friday the Thirteenth

Friday the Thirteenth 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 13t

Could not autowire. No beans of &#39;TbItemMapper&#39; type found. less... (Ctrl+F1) Checks autowiring prob

Intellij Idea开发工具在@Autowired或者@Resource注入XxxMapper接口时报如下错误: Could not autowire. No beans of 'TbItemMapper' type found. less... (Ctrl+F1)  Checks autowiring prob 解决方法如下,在 Intellij Idea中设置一下: Settings - Editor - Inspections - Spring - Spring Core - Cod

Thirteenth scrum meeting 2015/11/11

发布bug整理集结: 手机用户体验优化优化: (1)主界面和课程界面的字体规格以及界面结构不同 (2)课程图片的大小格式不统一,造成美观下降 ( 3 )按钮的位置不美观 平板用户体验: (1)Tab键在平板上,基本上特别不好按,需要很小心的按才能按到,不然就会按到下方课程 (2)Tab之间下方的滑动显示模块不知道是不是只有那么多,在平板用户中显示就是缺失了一块. (3)崩了 点击一些视频的时候会出现崩的情况 例子:计算机网络实验-实验10 总结:目前还有出现不经意间崩掉的情况,那种情况还没有找到