1.1.5 PROB Friday the Thirteenth
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的更多相关文章
- 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 ...
- USACO . Friday the Thirteenth
Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the mont ...
- USACO Section 1.1-3 Friday the Thirteenth
Friday the Thirteenth 黑色星期五 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数. 给出N年的一个 ...
- 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 ...
- soj1022. Poor contestant Prob
1022. Poor contestant Prob Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description As everyb ...
- SDUT 1941-Friday the Thirteenth(水)
Friday the Thirteenth Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 Is Friday the 13 ...
- 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 ...
- Friday the Thirteenth 黑色星期五 USACO 模拟 超级简单做法
1003: 1.1.3 Friday the Thirteenth 黑色星期五 时间限制: 1 Sec 内存限制: 128 MB提交: 8 解决: 8[提交] [状态] [讨论版] [命题人:外部 ...
- 洛谷P1202 [USACO1.1]黑色星期五Friday the Thirteenth
题目描述 13号又是一个星期五.13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数.给出N年的一个周期,要求计算1900年1月1日至1900+N- ...
随机推荐
- Android Studio 集成开发工具教学视频
简介 经过2年时间的研发,Google终于正式发布了面向Android开发者的集成开发环境Android Studio 1.2(稳定版).Android Studio是Google开发的一款面向And ...
- JMETER java.net.SocketException: Connection reset 报错解决方案
相关值解析MaxUserPort:最大动态端口数(Default = 5000, Max = 65534)TcpTimedWaitDelay:TCP等待延迟时间(30)TcpNumConnection ...
- 天坑!c++调用python,遭遇R6034问题
起源: AllMyTube下载核心,是c#组件调用c++dll,在dll中初始化Python运行环境.在工作目录有msvcr90.dll文件时,程序运行会弹出如下错误: R6034. -------- ...
- JMeter 通过JSON Extractor 插件来提取响应结果
接口响应结果,通常为HTML.JSON格式的数据,对于HTML的响应结果的提取,可以通过正则表达式,也可以通过XPath 来提取. 对于JSON格式的数据,可以通过正则表达式.JSON Extract ...
- tomcat关闭时Log4j2报错 Log4j Log4j2-TF-4-Scheduled-1 memory leak
出错信息: 23-Sep-2017 17:43:18.964 警告 [main] org.apache.catalina.loader.WebappClassLoaderBase.clearRefer ...
- vue如何使用rules对表单字段进行校验
基于element-ui 1.在代码中,添加属性::rule <el-form :model="form" :rules="rules" ref=&quo ...
- node 常用模块及方法fs,url,http,path
http://www.cnblogs.com/mangoxin/p/5664615.html https://www.liaoxuefeng.com/wiki/001434446689867b2715 ...
- Layui 写一个简单的后台页面
参考如下: 1.layui 官方文档 http://www.layui.com/doc/ 2.https://blog.csdn.net/huyanliang/article/details/7796 ...
- 简单的StringBuffer实现
package com.letv.test.base; import java.util.Arrays; public class StringBuffer { private char[] valu ...
- leetcode8:字符串转整数 (atoi)
实现 atoi,将字符串转为整数. 在找到第一个非空字符之前,需要移除掉字符串中的空格字符.如果第一个非空字符是正号或负号,选取该符号,并将其与后面尽可能多的连续的数字组合起来,这部分字符即为整数的值 ...