luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
2017-09-28 20:31
435 查看
题目描述
13号又是一个星期五。13号在星期五比在其他日子少吗?为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出N年的一个周期,要求计算1900年1月1日至1900+N-1年12月31日中十三号落在周一到周日的次数,N为正整数且不大于400.这里有一些你要知道的:
1、1900年1月1日是星期一.
2、4,6,11和9月有30天.其他月份除了2月都有31天.闰年2月有29天,平年2月有28天.
3、年份可以被4整除的为闰年(1992=4*498 所以 1992年是闰年,但是1990年不是闰年).
4、以上规则不适合于世纪年。可以被400整除的世纪年为闰年,否则为平年。所以,1700,1800,1900和2100年是平年,而2000年是闰年.
请不要调用现成的函数
请不要预先算好数据(就是叫不准打表)!
输入输出格式
输入格式:一个正整数n.
输出格式:
输入输出样例
输入样例#1:20
输出样例#1:
36 33 34 33 35 35 34
说明
题目翻译来自NOCOW。USACO Training Section 1.1
发现都不会写入门难度的题了…【跪烂
大概区分一下平年闰年
手动打个月份增加表
每个月的天数要%7
模拟一遍就好了
以及这题输出比较吊诡
小心
论printf的正确打开方式【debug10min
#include<bits/stdc++.h>
using namespace std;
template <typename T> void read(T &x){
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+ch-'0';
x*=f;
}
int month[12]={3,3,0,3,2,3,2,3,3,2,3,2};
int months[12]= {3,3,1,3,2,3,2,3,3,2,3,2};
int cnt[8];
int now=3;
bool yea(int num){
if(num%400==0) return true;
if(num%100==0) return false;
if(num%4==0) return true;
return false;
}
int main(){
int n;
read(n);
for(int i=1900;i<=1900+n-1;++i){
//cout<<yea(i)<<endl;
if(!yea(i)){
for(int j=0;j<12;++j){
now+=month[j];
if(now>7) now-=7;
++cnt[now];
}
}
else{
for(int j=0;j<12;++j){
now+=months[j];
if(now>7) now-=7;
++cnt[now];
}
}
}
printf("%d %d ",cnt[6],cnt[7]);
for(int i=1;i<=5;++i) printf("%d ",cnt[i]);
return 0;
}
相关文章推荐
- luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
- luogu1202 [USACO1.1]黑色星期五Friday the Thirteenth
- [USACO1.1]黑色星期五Friday the Thirteenth-洛谷 1202
- USACO 1.1 黑色星期五Friday the Thirteenth
- 【模拟】洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 [USACO1.1]黑色星期五Friday the Thirteenth
- 洛谷 1202 [USACO1.1] 黑色星期五 Friday the Thirteenth
- USACO 1.1 - Friday the Thirteenth(STL: map)
- 【USACO-Chapter1-1.1】【模拟】Friday the Thirteenth
- USACO 1.1 Friday the Thirteenth
- USACO--1.1Friday the Thirteenth+简单模拟
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO-Section1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth [日期]
- USACO Section 1.1 Friday the Thirteenth
- USACO1.1 Friday the Thirteenth 比较分析
- USACO 1.1 Friday the Thirteenth
- USACO-Section1.1 Friday the Thirteenth[日期]
- USACO 1.1 Friday the Thirteenth