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!

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

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

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

【模拟】洛谷 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 ...

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

【题目描述】 一块N x N(1 1:转90度:图案按顺时针转90度。 2:转180度:图案按顺时针转180度。 3:转270度:图案按顺时针转270度。 4:反射:图案在水平方向...

【USACO】洛谷P1518 两只塔姆沃斯牛(模拟)

题目描述两只牛逃跑到了森林里。农夫John开始用他的专家技术追捕这两头牛。你的任务是模拟他们的行为(牛和John)。追击在10x10的平面网格内进行。一个格子可以是:一个障碍物, 两头牛(它们总在一起...

USACO-Section 3.2 Spinning Wheels(模拟)

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

Spinning Wheels_usaco3.2_模拟

题目描述 Description一架纺车有五个纺轮(也就是五个同心圆),这五个不透明的轮子边缘上都有一些缺口。这些缺口必须被迅速而准确地排列好。每个轮子都有一个起始标记(在0度),这样所有的轮子都可以...

USACO 1.4.1 Packing Rectangles —— 暴力+ 模拟

Packing Rectangles IOI 95   The six basic layouts of four rectangles Four rectangles are given. Find...

USACO 1.1.4 Broken Necklace(模拟)

做这题做了一个下午,都快崩溃了。说下要点: 1、要注意'w'这种特殊情况,到某位置时,注意左边、右边是'w'的情况。 2、得把整个项链看出循环队列,所以指针移动时注意mod。 3、我用的还是暴力...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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