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校验文件MD5值

    import hashlib import os def GetFileMd5(filename): if not os.path.isfile(filename): return myHash = ...

  2. PCIE错误分析

    前面的文章提到过,PCI总线中定义两个边带信号(PERR#和SERR#)来处理总线错误.其中PERR#主要对应的是普通数据奇偶校检错误(Parity Error),而SERR#主要对应的是系统错误(S ...

  3. Month format:number to English abbre

    ``` DATA LV_MONTH TYPE FCKTX. CLEAR:LV_MONTH,lv_date. SELECT SINGLE KTX INTO LV_MONTH FROM T247 WHER ...

  4. angular $digest 运行10次货10次以上会抛出异常

    今天在做项目时,遇到一个问题,红圈处输入其他数字(n多次)也不会报异常,但是有一种特例,即0,1,0,1,0,1这种顺序输入时,输入第13次时,页面计算结果(蓝色圆圈)不会更新,困扰了1天多这个问题, ...

  5. ASP.NET Core 项目简单实现身份验证及鉴权

    ASP.NET Core 身份验证及鉴权 目录 项目准备 身份验证 定义基本类型和接口 编写验证处理器 实现用户身份验证 权限鉴定 思路 编写过滤器类及相关接口 实现属性注入 实现用户权限鉴定 测试 ...

  6. java分布式电子商务云平台b2b b2c o2o需要准备哪些技术??

    技术解决方案 开发语言: java.j2ee 数据库:mysql JDK支持版本: JDK1.6.JDK1.7.JDK1.8版本 核心技术:分布式.云服务.微服务.服务编排等. 核心架构: 使用Spr ...

  7. left join中where与on的区别

    举例进行说明,我们现在有两个表,即商品表(products)与sales_detail(销售记录表).我们主要是通过这两个表来对MySQL关联left join 条件on与where 条件的不同之处进 ...

  8. Vue history模式支持ie9

    vue 路由里面的history能让浏览器显示平常一样的链接,可以去掉#这种,但是在ie9下面会强制变成hash,因为history不支持ie9自动降级,可能就会影响美感,解决:可以在路由里面添加fa ...

  9. vue公共

    1 需求:在做项目的过程中发现,有一些功能是公共的,于是就想把这些公共的功能抽出来,做成独立的模块,别的项目需要用到,直接引用这个模块 2 问题: 前端:1 是用vue做的,vue的跳转是通过rout ...

  10. 信号(signal)

    1.信号本质 1)信号是一种软件中断,是在软件层次上对中断的模拟: 2).在日常生活中也有很多信号,比如常见的红绿灯信号,我们看见红灯就停下,linux中的信号也是类似的,它提供一种机制告诉某个进程在 ...