The Same Calendar
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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
inputCopy
2016
outputCopy
2044
inputCopy
2000
outputCopy
2028
inputCopy
50501
outputCopy
50507
Note
Today is Monday, the 13th of June, 2016.
题意:找出下一个和今年有相同日期(日期对应星期相同)的年份 |
思路:
很基础的一个东西,首先日期相同肯定平闰年也要相同,并且观察发现
365%7 == 1
366%7 == 2
最后得到的年份肯定也是经过n个7的周期得到的。
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
#include <climits>
#include <string>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#define maxn 200005
using namespace std;
int leap(int x)
{
if(x%400==0) return 366;
if(x%4==0&&x%100!=0) return 366;
return 365;
}
int main()
{
int n;
cin>>n;
int tmp = n+1;
int mod = leap(tmp)%7;
while(mod!=0||leap(n)!=leap(tmp))
{
tmp++;
mod = (mod + leap(tmp))%7;
}
cout<<tmp<<endl;
return 0;
}