链接:http://acm.hust.edu.cn/vjudge/problem/401743/origin
题目:
题意:找到下一个整个日历和今年一模一样的年份(也就是某月的某一天同样是星期几)。
分析:首先要判断是不是闰年,因为要保证下一个年份跟这个年份同闰,在之后保证星期几是相同的,只要这两个不同年份的同一月的同一天之间相差的天数是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).
题意:找到下一个整个日历和今年一模一样的年份(也就是某月的某一天同样是星期几)。
分析:首先要判断是不是闰年,因为要保证下一个年份跟这个年份同闰,在之后保证星期几是相同的,只要这两个不同年份的同一月的同一天之间相差的天数是7的整数倍就好了。
题解:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
int y;
bool isren(int year)
{
if(year%400==0||(year%4==0&&year%100!=0))
return true;
return false;
}
int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&y))
{
int ans=0;
bool renflag=false;
if(isren(y))
{
ans+=2;//366%7
renflag=true;
}
else
ans+=1;//365
for(int i=1;;i++)
{
if(isren(++y))
ans+=2;
else
ans+=1;
if(ans%7==0&&renflag&&isren(y+1))
break;
if(!renflag&&ans%7==0&&!isren(y+1))
break;
}
y++;
printf("%d\n",y);
}
return 0;
}