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代码

 /*
ID: luopengting
PROG: friday
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = ;
int year[maxn];
int days[];
int m[] = {, , , , , , , , , , , }; //记得12月份摆在第一
// 12, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
int tt;
void init()
{
for(int i = ; i < + maxn; i++)
{
if((i % == ) || ((i % ) && (i % == )))
{
year[i - ] = ;
}
else
{
year[i - ] = ;
}
}
}
void deal(int n)
{
tt = - ;
for(int i = ; i < n; i++)
{
for(int j = ; j < ; j++)
{
tt += m[j];
if(year[i] && j == )//闰年
{
tt++;
}
tt %= ;
days[tt]++;
}
}
}
int main()
{
freopen("friday.in","r",stdin);
freopen("friday.out","w",stdout);
init();
int n;
while(cin >> n)
{
memset(days, , sizeof(days));
deal(n);
int i;
for(i = ; i < ; i++)
{
cout << days[i] << " ";
}
cout << days[i] << endl;
}
return ;
}

1.1.5 PROB Friday the Thirteenth的更多相关文章

  1. USACO section 1.1 C++题解

    USACO section1.1:DONE 2017.03.03 TEXT Submitting Solutions DONE 2017.03.04 PROB Your Ride Is Here [A ...

  2. USACO . Friday the Thirteenth

    Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the mont ...

  3. USACO Section 1.1-3 Friday the Thirteenth

    Friday the Thirteenth 黑色星期五 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数. 给出N年的一个 ...

  4. Could not autowire. No beans of 'TbItemMapper' type found. less... (Ctrl+F1) Checks autowiring prob

    Intellij Idea开发工具在@Autowired或者@Resource注入XxxMapper接口时报如下错误: Could not autowire. No beans of 'TbItemM ...

  5. soj1022. Poor contestant Prob

    1022. Poor contestant Prob Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description As everyb ...

  6. SDUT 1941-Friday the Thirteenth(水)

    Friday the Thirteenth Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述  Is Friday the 13 ...

  7. USACO-Friday the Thirteenth(黑色星期五)-Section1.2<3>

    [英文原题] Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of t ...

  8. Friday the Thirteenth 黑色星期五 USACO 模拟 超级简单做法

    1003: 1.1.3 Friday the Thirteenth 黑色星期五 时间限制: 1 Sec  内存限制: 128 MB提交: 8  解决: 8[提交] [状态] [讨论版] [命题人:外部 ...

  9. 洛谷P1202 [USACO1.1]黑色星期五Friday the Thirteenth

    题目描述 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900+N- ...

随机推荐

  1. python note 12 生成器、推导式

    1.生成器函数 # 函数中如果有yield 这个函数就是生成器函数. 生成器函数() 获取的是生成器. 这个时候不执行函数# yield: 相当于return 可以返回数据. 但是yield不会彻底中 ...

  2. ListBox设置背景色无效的问题。 listview类似

    <Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Template"&g ...

  3. 新建VS工程与填坑:解决方案与项目不在同一目录

    A.新建项目->空工程 B.添加依赖库 1.属性->C/C++->附加包含目录 注:添加头文件目录,必须指向子文件夹 2.属性->链接器->常规->附加库目录 注: ...

  4. 分析easyswoole3.0源码,Trace组件(四)

    前文,我们访问地址的时候服务端会输出类似trace信息.那么原理是什么呢?其实es3已经把这个独立出来作为单独组件了,名字叫做Trace组件 在demo里的调用原理是 EasySwooleEvent: ...

  5. 201771010134杨其菊《面向对象程序设计(java)》第十六周学习总结

    第十六周学习总结 第一部分:理论知识 1. 程序是一段静态的代码,它是应用程序执行的蓝本.进程是程序的一次动态执行,它对应了从代码加载.执行至执行完毕的一个完整过程.操作系统为每个进程分配一段独立的内 ...

  6. eclipse创建scrapy项目

    1. 您必须创建一个新的Scrapy项目. 进入您打算存储代码的目录中(比如否F:/demo),运行下列命令: scrapy startproject tutorial 2.在eclipse中创建一个 ...

  7. [C#.Net]Window服务调用外部程序

    最近遇到要做回传服务内增加开关,可以自定义运行一些脚本已方便收集PC状态,发现Bat始终无法运行,上网找了半天才发现和Session0有关,也就是程序有不同级别的访问权限,Vista以上版本为了安全因 ...

  8. Startls Back 引起的 win10升级之后的闪屏问题

    win10 更新之后出现闪频问题. 有人说是和startls back 有关,需要卸载startls back, 但是进入安全模式下显示此 程序无法打开,无法卸载. 后来看到有人更新到startls ...

  9. 4月23日 db 命令操作 和表操作

    1内容回顾: # 补充的知识点 # server端肯定是确定下来的 # mysql的客户端 # mysql.exe 直接在命令行就可以运行的 (学习阶段用) # navicat等可视化的客户端,是第三 ...

  10. linux系统下部署DNS反向解析

    DNS服务概述 DNS(Domain Name System)域名系统,能够提供域名与IP地址的解析服务. 反向解析 反向解析是从IP地址到域名的解析过程.主要作用于服务器的身份验证. 部署反向解析 ...