Educational Codeforces Round 13 B
2016-06-15 12:18
357 查看
[b]Description[/b]
The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.
Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100(https://en.wikipedia.org/wiki/Leap_year).
Input
The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.
Output
Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.
Examples
input
output
input
output
input
output
Note
Today is Monday, the 13th of June, 2016.
这个我使用基姆拉尔森计算公式求相同日期如果星期数相同,就看做日历相同。。这里我是拿1月1,3月1,和12月1比较。都相同就是相同的。。
其实正确解法是计算每年相隔天数。。如果是7的倍数而且平闰相同就是结果。
The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.
Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100(https://en.wikipedia.org/wiki/Leap_year).
Input
The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.
Output
Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.
Examples
input
2016
output
2044
input
2000
output
2028
input
50501
output
50507
Note
Today is Monday, the 13th of June, 2016.
这个我使用基姆拉尔森计算公式求相同日期如果星期数相同,就看做日历相同。。这里我是拿1月1,3月1,和12月1比较。都相同就是相同的。。
其实正确解法是计算每年相隔天数。。如果是7的倍数而且平闰相同就是结果。
#include<stdio.h> #include<string> #include<iostream> #include<math.h> #include<time.h> #include <stdlib.h> using namespace std; int Day_weak(int year,int month,int day) { if(month==1||month==2) { month +=12; --year; } int week = -1; week=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+1; return week; // 输出-1为错误 } int main() { int a,b,c; int i; cin>>a; for(i=a+1;i<=1000000;i++) { if(Day_weak(a,1,1)==Day_weak(i,1,1)&&Day_weak(a,3,1)==Day_weak(i,3,1)&&Day_weak(a,12,1)==Day_weak(i,12,1)) { break; } } cout<<i<<endl; return 0; }
相关文章推荐
- Coding过程中遇到的一些bug
- 斗天斗地斗控件 -- 与 Flyout 控件的斗争史
- 实现简单天气预报
- 强悍的命令行 —— 编辑出错的命令
- Leetcode 39. Combination Sum
- LeetCode:Factorial Trailing Zeroes
- yii2高级模板安装和yii migrate的使用
- Codeforces Round #357 (Div. 2)-C. Heap Operations
- 闪屏界面的切换
- 数据库基础知识总结
- SoapUI使用方法-01发送http请求
- document的createDocumentFragment()方法
- 小试python-MySQLdb 安装和使用
- 面试题24 二叉搜索树的后序遍历序列
- jquery无法控制checkbox是否选中
- linux基础之压缩与归档
- 基于JavaScript代码去掉H5页面中的头尾及广告部分(支持 Android 和 iOS)2(难度升级)
- Android常用开源工具(1)-Dagger2入门
- /etc/fstab发生错误或磁盘错误导致系统无法启动的修复方法
- Android中framework层下添加aidl编译说程序包不存在