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- ...
随机推荐
- 初学Python:面向对象总结
2019-04-16 Python 3x 一. 面向对象的含义和特性 面向对象是将世界中的具体事物进行抽象,从而能够更好的帮助我们归纳总结,解决复杂问题的一种解决问题的思路. 面向对象的三个特性——封 ...
- python字符串之format格式化函数
学习中~ 觉得应该系统地学习一下python,今天学习了字符串,以下是自己的笔记. 首先说一下format函数,用{}和:代替了%,比如: >>>“{} {} {}”.format( ...
- Mybatis SqlsessionFactory
在Mybatis 与 Spring 进行整合的时候,我们会进行sqlSessionFactory 的配置,来创建sqlSessionFactory 对象:如下: <bean id="s ...
- Struts2源码解析2
看了前面一节对Struts2各个模块运行有了大概了解,也对调用的函数有了一定的了解,本节希望打断点跑一个Struts2例子! 还是放在struts2结构图: 一:项目启动后解析web.xml文件,会解 ...
- redis缓存雪崩,缓存穿透,缓存击穿的解决方法
一.缓存雪崩 缓存雪崩表示在某一时间段,缓存集中失效,导致请求全部走数据库,有可能搞垮数据库,使整个服务瘫痪. 使缓存集中失效的原因: 1.redis服务器挂掉了. 2.对缓存数据设置了相同的过期时间 ...
- Synchronized和Lock的区别
①synchronized是jvm的关键字,Lock是Java类: ②synchronized会自动释放锁,而Lock需要在finally语句中主动释放锁,否则会造成死锁 ③用synchronized ...
- 安装pygame出现is not a supported wheel on this platform解决办法
安装python库pygame时出现如下错误: 查看python的版本是否与之匹配,发现版本不匹配问题 例如1.我的python3.6是32位的,就只能安装cp36的:结果发现安装还是出现问题: 2. ...
- 8.Redis内存分配
8.Redis内存分配8.1 内存消耗8.1.1 内存使用统计8.1.2 内存消耗划分8.1.3 子进程内存消耗8.2 内存管理8.2.1 设置内存上限8.2.2 动态调整内存上限8.2.3 内存回收 ...
- 使用PHP实现手机端APP支付宝的支付功能
最近应业务需求,做了支付宝支付和微信支付,今天分享一下手机端app支付宝支付对接流程,实际开发过程是前后端分离,前端调用后端API接口,实现功能返回数据,我所用的跨挤啊为TP5,大致可以分为四步: 1 ...
- pymysql-python爬虫数据存储准备
mongodb 和mysql 在使用哪个数据库 来存储数据上 小哥还是纠结了一下下. 很多爬虫教程都推荐mongodb 优势是速度快 因为我已经本机安装了一下 php开发环境,mysql是现成的, s ...