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年,找出13号所在的星期出现的次数.

解题思路:
1900年的1月1日为星期一,然后就是闰年的判定(能被400整除或者能被4整除同时不能被100整除的年份).

AC代码:

/*
ID:Reckful
LANG:C++
TASK:friday
*/
#include<stdio.h>
int mouth[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 isLeap(int n)
{if((n%400==0)||(n%4==0&&n%100!=0))    return true;return false;
}
int day[8] = {0};
int main()
{//freopen("friday.in","r",stdin);//freopen("friday.out","w",stdout);int n;scanf("%d",&n);int days = 0;for(int i = 0;i < n;i++){int flag = isLeap(1900+i);for(int i = 1;i <= 12;i++){day[(days+12)%7+1]++;days += mouth[i][flag];}}printf("%d %d %d %d %d %d %d\n",day[6],day[7],day[1],day[2],day[3],day[4],day[5]);return 0;
}

USACO 1.1.3 - Friday the Thirteenth(模拟)相关推荐

  1. USACO—1.1.3 Friday the Thirteenth 黑色星期五

    题目描述: 1.1.3 Friday the Thirteenth 黑色星期五 (friday.pas/c/cpp) 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序 ...

  2. usaco 1.1.3

    usaco 1.1.3 - Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13 ...

  3. 【from zero to zero】noip2017

    from zero to zero 洛谷首页的倒计时不知道什么时候就变成了六字开头. 到底还是太弱了. 生病又拖了很多的时间. 听了很多的算法,自己写起来却非常困难. 也许要在累倒前做一些事情呢. 从 ...

  4. 洛谷 P1207 [USACO1.2]双重回文数 Dual Palindromes

    P1207 [USACO1.2]双重回文数 Dual Palindromes 题目描述 如果一个数从左往右读和从右往左读都是一样,那么这个数就叫做"回文数".例如,12321就是一 ...

  5. 洛谷 P1205 [USACO1.2]方块转换 Transformations

    题目描述 一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案.写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式: 1:转90度:图案按顺时针 ...

  6. [USACO1.1]贪婪的送礼者Greedy Gift Givers

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

  7. 洛谷 P2728 纺车的轮子 Spinning Wheels

    P2728 纺车的轮子 Spinning Wheels 题目背景 一架纺车有五个纺轮(也就是五个同心圆),这五个不透明的轮子边缘上都有一些缺口.这些缺口必须被迅速而准确地排列好.每个轮子都有一个起始标 ...

  8. 洛谷 P1203 [USACO1.1]坏掉的项链Broken Necklace

    P1203 [USACO1.1]坏掉的项链Broken Necklace 题目描述 你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N<=350),珠子是随意安排的. 这里是 ...

  9. USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)

    这题可真是又让我找到了八数码的感觉...哈哈.首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了.这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我发现 ...

  10. USACO 1.1 Friday the Thirteenth

    题目来源:USACO 1.1 原题目: Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does ...

最新文章

  1. CLion报错解决:allocating an object of abstract class type--unimplemented pure virtual method
  2. 难道这是残差结构的本质(addnorm)
  3. Windows10 JDK9安装及配置环境变量与Eclipse安装
  4. linux中yum教程,CentOS7下yum使用
  5. 关于TableView中图片的延时加载(转)
  6. svg mysql_!!!常用SVG代码
  7. Java中的数组,java开发面试笔试题
  8. css悬停动画,animate.css:悬停脚本上的动画
  9. bzoj 1124: [POI2008]枪战Maf(贪心)
  10. 小系统单据自动生成存储过程
  11. 背景差分检测物体,背景白点去除
  12. PHP设计模式——桥接模式
  13. iOS 8 自适应 Cell
  14. C#实现四舍五入和JavaScript实现四舍五入
  15. 从认知语言学的角度来看计算机没有,从认知语言学的角度来看「ところ」
  16. 手机整人脚本html,教大家用vbs代码制作恶搞整人
  17. 基于CBOW网络手动实现面向中文语料的word2vec
  18. 【转】这么多计算几何题目,够你练了
  19. 饭店点餐系统之系统网络结构
  20. 无忧看片,Python黑科技神奇去除马赛克

热门文章

  1. oracle 范鑫_快速理解数据库中的索引(Indexes in Database)
  2. TIdTCPClient 详解
  3. (十)Redis集群(JedisCluster)Jedis客户端命令详解
  4. 【NPDP】大师级管理人物盘点:现代管理之父-彼得·德鲁克
  5. css 标点符号换行,字母汉字可以换行 标点符号不能换行_html/css_WEB-ITnose
  6. Chinese-Whisper聚类算法
  7. phalapi做登录检测_Phalapi使用教程
  8. 30天150万公里,韦布望远镜抵达终点成功入轨,18镜合一进行时
  9. Windows消息ID大全
  10. 大数据培训:Hadoop生态系统圈