SDUT 1941-Friday the Thirteenth(水)
Friday the Thirteenth
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描写叙述
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 non-negative and will not exceed 400.
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
输入
One line with the integer N.
输出
For each input, there is an output correspond to it, each have the following format:
Seven space separated integers on one line. These integers represent the number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, ..., Friday.
演示样例输入
20
演示样例输出
36 33 34 33 35 35 34
刷道存在感。。
题意 :问从1900年往后的n年里,每一个月的13号分布在星期1到7的情况。。这算哈希?反正暴力就能够了
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#define ll long long
using namespace std;
const int INF=1<<27;
const int maxn=1010;
int n,num[8];
bool is_leap(int year)
{
if((year%4==0&&year%100!=0)||year%400==0)
return 1;
else
return 0;
}
void solve()
{
memset(num,0,sizeof(num));
int xx=1;
for(int year=1900;year<=1900+n-1;year++)
{
for(int month=1;month<=12;month++)
{
int tem;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
tem=31;
else if(month==4||month==6||month==9||month==11)
tem=30;
else if(month==2&&is_leap(year))
tem=29;
else if(month==2&&!is_leap(year))
tem=28;
int tag=(xx+12)%7==0? 7:(xx+12)%7;
xx=(xx+tem)%7==0?7:(xx+tem)%7;
num[tag]++;
}
}
printf("%d %d",num[6],num[7]);
for(int i=1;i<=5;i++)
printf(" %d",num[i]);
puts("");
}
int main()
{
while(~scanf("%d",&n))
solve();
return 0;
}
SDUT 1941-Friday the Thirteenth(水)的更多相关文章
- sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)
n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you w ...
- sdut 2163:Identifiers(第二届山东省省赛原题,水题)
Identifiers Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Identifier is an important c ...
- sdut 2154:Shopping(第一届山东省省赛原题,水题)
Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...
- sdut 2158:Hello World!(第一届山东省省赛原题,水题,穷举)
Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...
- USACO . Friday the Thirteenth
Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the mont ...
- sdut 2445 小学数学
小学数学 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu.cn/sdutoj/p ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- Luogu USACO Training 刷水记录
开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
随机推荐
- 寻找SQL注入点
如果要对一个网站进行SQL注入攻击,首先就需要找到存在SQL注入漏洞的地方,也就是寻找所谓的注入点.可能的SQL注入点一般存在于登录页面.查找页面或添加页面等用户可以查找或修改数据的地方. 最常用的寻 ...
- Spring Tool Suite 使用自带maven速度慢---修改settings.xml更新mirror方法
(1)打开sts,windows --> preference,找到maven,并设置如下. (2)修改该文件,如下 <mirror> <id>nexus-aliyun& ...
- 【FAI】七日年化收益与万份收益的理解
七日年化收益:其实指的一年的收益(应该忽略”七日”),这里的七日指的是取最近七日年化的结果 万份收益:每万元每天的收益 可以使用下图来清晰识别: 例子: 10000元按照5%的七日年化收益计算的话: ...
- HTTP协议详解之User Agent篇
•User Agent:用户代理 指浏览器他的信息包括硬件平台.系统软件.应用软件和用户个人偏好.用户代理不仅仅指浏览器,还包括搜索引擎. •为什么所有浏览器的User Agent都带有Mozilla ...
- SQL Union作用
动态构造一个SQL语句然后执行,构造动态语句的查询语句如下 SELECT REPLACE(WMSYS.WM_CONCAT(STR),',',' UNION ') FROM (SELECT 'SELEC ...
- 示例:Socket应用之简易聊天室
在实际应用中,Server总是在指定的端口上监听是否有Client请求,一旦监听到Client请求,Server就会启动一个线程来响应该请求,而Server本身在启动完线程之后马上又进入监听状态. 示 ...
- jQuery+PHP动态显示(项目)实时时间和倒计时
jQuery动态显示当前时间: html代码:<div id="current_time"></div> setInterval()使用:setInt ...
- linux下修改文件权限
加入-R 参数,就可以将读写权限传递给子文件夹例如chmod -R 777 /home/mypackage那么mypackage 文件夹和它下面的所有子文件夹的属性都变成了777777是读.写.执行权 ...
- 【LeetCode】128. Longest Consecutive Sequence
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
- RabbitMQ概念及环境搭建(四)RabbitMQ High Availability
#################################################### RabbitMQ High Availability #################### ...