USACO firday 模拟

原创 2011年01月11日 17:19:00
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 non-negative and will not exceed 400.

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: topcoder3

PROG: friday

LANG: C++

*/

 

#include<fstream>

 

using namespace std;

 

int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int ans[7];

 

ifstream fin("friday.in");

ofstream fout("friday.out");

 

int main()

{

         int n,i,d=0,y,c=0,t,j;

         fin>>n;

         for(i=1900;i<(1900+n);i++)

         {

                   if(((i%4==0)&&(i%100!=0))||(i%400==0))

                   {

                            m[1]=29;

                            y=366;

                   }

                   else

                   {

                            m[1]=28;

                            y=365;

                   }

                   ans[(13+c)%7]++;

                   t=13+c;

                   for(j=1;j<12;j++)

                   {

                            t=t+m[j-1];

                            ans[t%7]++;

                   }

                   d=y+c;

                   c=d%7;

         }

         fout<<ans[6]<<" "<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<" "<<ans[4]<<" "<<ans[5]<<endl;

         return 0;

}

数据:

USER: bing shen [topcode3]
TASK: friday
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3012 KB]
   Test 2: TEST OK [0.000 secs, 3012 KB]
   Test 3: TEST OK [0.000 secs, 3012 KB]
   Test 4: TEST OK [0.022 secs, 3012 KB]
   Test 5: TEST OK [0.011 secs, 3012 KB]
   Test 6: TEST OK [0.000 secs, 3012 KB]
   Test 7: TEST OK [0.000 secs, 3012 KB]
   Test 8: TEST OK [0.000 secs, 3012 KB]

All tests OK.

Your program ('friday') produced all correct answers! This is your submission #2 for this problem. Congratulations!

Here are the test data inputs:

------- test 1 -------
1
------- test 2 -------
2
------- test 3 -------
5
------- test 4 -------
13
------- test 5 -------
45
------- test 6 -------
100
------- test 7 -------
256
------- test 8 -------
400
Keep up the good work!

Thanks for your submission!

NOIP模拟赛1 飞盘队(貌似又是USACO上面的题) MR_HE改编 子集生成+中途相遇+dp

【问题描述】 农夫顿因开始玩飞盘之后,约翰也打算让奶牛们享受飞盘的乐趣。他打算组建一只自己的奶牛飞盘队。 他的N只奶牛里,每只都有一个飞盘水准指数R_i,约翰要选出其中一些奶牛来参加他的飞...

USACO 1.5 Superprime Rib 特殊的质数肋骨(模拟)

【USACO1.5.3】Superprime Rib 特殊的质数肋骨 Time Limit:10000MS  Memory Limit:65536K Total Submit:56 Accepte...

【USACO题库】1.5.2 Prime Palindromes回文质数(模拟,打表)

【USACO题库】1.5.2 Prime Palindromes回文质数

模拟退火算法初探——[usaco 5.2]electic fences总结

今天心血来潮自己学习模拟退火,听名字就感觉高端大气上档次,老师说:这是一个拼人品的算法,他也不熟。建议我先不学,毕竟高大上,我喜欢。 下面谈谈今天的学习: 看了一些材料什么的,表示无爱,什...

USACO-Section 3.2 Spinning Wheels(模拟)

数据范围很小,直接模拟即可 用一个cur[i][j]数组表示第i个轮子当前角度j是否有空隙 需要注意的是有空隙的角度是闭区间,即[s,s+e]均有空隙...

USACO Section 3.2 Spinning Wheels - 纯模拟的大水题

主要还是题意~~有点长~感觉确实也讲得不是太清晰... 反正这五个轮子有那么一个点是相通过去的就ok了...并且要在整数秒时相通..    纯模拟..因为不管速度是多少..反正在360秒后都会转回来...
  • kk303
  • kk303
  • 2011年12月20日 12:02
  • 583

【模拟】洛谷 P1204 [USACO1.2]挤牛奶Milking Cows

题目描述三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶。第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒。第二个农民在700秒开始,在 1200秒结束。第三个农民在1500秒开始...

【模拟】洛谷 P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers

题目描述对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少。在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那些将收到他的礼物的人。然而,在任何一群朋友中,...

The Tamworth Two_usaco2.4.1_模拟

DESCRIPTIONA pair of cows is loose somewhere in the forest. Farmer John is lending his expertise to ...
  • jpwang8
  • jpwang8
  • 2016年08月28日 12:34
  • 136

【USACO-Chapter1-1.2】【模拟】Transformations

【题目描述】 一块N x N(1 1:转90度:图案按顺时针转90度。 2:转180度:图案按顺时针转180度。 3:转270度:图案按顺时针转270度。 4:反射:图案在水平方向...
  • njlcazl
  • njlcazl
  • 2012年06月17日 20:32
  • 316
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:USACO firday 模拟
举报原因:
原因补充:

(最多只允许输入30个字)