博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SDUT 1941-Friday the Thirteenth(水)
阅读量:5050 次
发布时间:2019-06-12

本文共 2817 字,大约阅读时间需要 9 分钟。

Friday the Thirteenth

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描写叙述

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

 

输入

there are several test cases, each have the following format: 
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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long longusing 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; }

转载于:https://www.cnblogs.com/yangykaifa/p/6729442.html

你可能感兴趣的文章
python入门作业---ATM+购物商场程序(2)
查看>>
仿射函数
查看>>
(一) Keras 一元线性回归
查看>>
Unity的50个使用技巧(2016 Edition)
查看>>
HDU 2050(折线分割平面)
查看>>
sql 存储过程—分页获取信息
查看>>
okhttp3 get post 简单封装
查看>>
基础网络相关概念
查看>>
2010年初关注的技术
查看>>
Git——新手入门与上传项目到远程仓库GitHub
查看>>
Java基础知识脑图
查看>>
VMware安装CentOS 提示:已将该虚拟机配置为使用 64 位客户机操作系统。但是,无法执行 64 位操作。解决方案...
查看>>
iOS:UIWebView scrollView 的分页滑动问题
查看>>
【Movie】绿皮书
查看>>
python发送邮件 示例
查看>>
SpringMVC与Struts2的区别
查看>>
课后作业-阅读任务-阅读提问-3
查看>>
Latches and Tuning:Buffer Cache
查看>>
c++:空构造空析构的益处之一
查看>>
推荐系统 BPR 算法求解过程
查看>>