当前位置:网站首页>洛谷P1202 黑色星期五Friday the Thirteenth
洛谷P1202 黑色星期五Friday the Thirteenth
2022-08-07 04:53:00 【CLH_W】
题目描述
1313 号又是一个星期五,那么 1313号在星期五比在其他日子少吗?
为了回答这个问题,写一个程序,要求计算每个月的十三号落在周一到周日的次数。给出 nn 年的一个周期,要求计算 19001900 年 11 月 11 日至 1900+n-11900+n−1 年 1212 月 3131 日中十三号落在周一到周日的次数。
这里有一些你要知道的:
1、19001900 年 11 月 11 日是星期一。
2、4,6,114,6,11 和 99 月有 3030 天,其他月份除了 22 月都有 3131 天,闰年 22 月有 2929 天,平年 22 月有 2828 天。
3、年份可以被 44 整除的为闰年 ( 1992=4*4981992=4∗498 所以 19921992 年是闰年,但是 19901990 年不是闰年 )。
4、以上规则不适合于世纪年。可以被 400400 整除的世纪年为闰年,否则为平年。所以,1700,1800,1900,21001700,1800,1900,2100 年是平年,而 20002000 年是闰年。
输入格式
一个正整数 nn。
输出格式
依次输出周六、日、一、二、三、四、五在 1313 日出现的次数。
输入输出样例
输入 #1复制
20
输出 #1复制
36 33 34 33 35 35 34
说明/提示
【数据范围】
对于 100%100% 的数据,1\le n \le 4001≤n≤400。
题目翻译来自NOCOW。
USACO Training Section 1.1
上代码:
#include<bits/stdc++.h>
using namespace std;
int n,xin=6;
int yue[13]={
0,31,28,31,30,31,30,31,31,30,31,30,31}/*记录每月的天数*/,ans[6];
bool run(int nian){
//函数判闰年
if(nian%400==0)
return true;
if(nian%100==0)
return false;
if(nian%4==0)
return true;
return false;
}
int main(){
cin>>n;
for(int i=1900;i<=1900+n-1;i++){
//按思路循环
for(int j=1;j<=12;j++){
xin+=yue[j];
if(j==2)
if(run(i))
xin++;
xin%=7;
ans[xin]++;
}
}
cout<<ans[6]+1<<" "<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<" "<<ans[4]<<" "<<ans[5]<<" "<<endl;//输出,ans[0]即为周日。
return 0;
}
边栏推荐
- 一本通1225——金银岛
- 多线程之原子数组
- Differences in the soft serial port bit time function of different series of STC microcontrollers
- Network cable
- 2022牛客多校六 B-Eezie and Pie (dfs)
- Talk about 7 magic skills of Redis memory optimization
- MySQL - 存储过程和函数
- Backtracking and its Simple Question Example
- Brush the title "Sword Finger Offer" day11
- Linear Algebra Study Notes 4-6: Null Space, Column Space, Row Space, Left Null Space, Elementary Row Transformation, Test Questions of Matrix
猜你喜欢

不是吧,10:00面试,10:08就出来了 ,问的实在是太...

Reading Notes - RetinaFace: Single-stage Dense Face Localisation in the Wild

自动化运维工具——ansible概述和部署

多线程进阶

量化风控的规则开发,如何更好做策略定规则,抓坏人

4G dtu remote wireless meter reading

Project management knowledge points
![[TypeScript Notes] 03 - TS Type Declaration File](/img/8d/bf4a1763e25c4bc73f5f2138a9147e.png)
[TypeScript Notes] 03 - TS Type Declaration File

What is SaaS service platform software?

谁说专科学历找不到测试工作?自学测试,北京第一份工作12K。
随机推荐
Small P weekly, Vol. 14
typescript83-属性的默认值
Golang map结构体成员不能修改的问题
typescript88-任务案例
Tables that come with MySQL
2022 Niu Ke Duo School Six M-Z-Game on grid (dynamic programming)
终端数据加密
Tips for recording WPF (2) 16-30
Brush the title "Sword Finger Offer" day11
One Pass 1225 - Treasure Island
【Metaverse系列一】元宇宙的奥秘
Implementing a simple address book in C language
Excel单元格显示数据与实际数据不一致的设置与清除
The fourth virtual camera: who is calling the v4l2_camera_HAL camera driver
多线程进阶
OK-MY TODO LIST
2022-08-06:给定一个数组arr,长度为N,arr中所有的值都在1~K范围上, 你可以删除数字,目的是让arr的最长递增子序列长度小于K。 返回至少删除几个数字能达到目的。 N <= 10^4
Automated operation and maintenance tools - ansible overview and deployment
ansible——playbook剧本的讲解与应用
线性代数学习笔记4-3:求解齐次线性方程组Ax=0、消元法、行最简阶梯型矩阵RRFE