您的位置:首页 > 其它

HDU 6112 今夕何夕 【数学公式】 (2017"百度之星"程序设计大赛 - 初赛(A))

2017-08-13 11:32 337 查看


今夕何夕

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1295    Accepted Submission(s): 455


Problem Description

今天是2017年8月6日,农历闰六月十五。

小度独自凭栏,望着一轮圆月,发出了“今夕何夕,见此良人”的寂寞感慨。

为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年里的同一个日子,和今天的星期数一样?比如今天是8月6日,星期日。下一个也是星期日的8月6日发生在2023年。

小贴士:在公历中,能被4整除但不能被100整除,或能被400整除的年份即为闰年。

 

Input

第一行为T,表示输入数据组数。

每组数据包含一个日期,格式为YYYY-MM-DD。

1 ≤ T ≤ 10000

YYYY ≥ 2017

日期一定是个合法的日期

 

Output

对每组数据输出答案年份,题目保证答案不会超过四位数。

 

Sample Input

3
2017-08-06
2017-08-07
2018-01-01

 

Sample Output

2023
2023
2024

 

Source

2017"百度之星"程序设计大赛
- 初赛(A)

 

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  6113 6112 6111 6110 6109 

 

Statistic | Submit | Discuss | Note

题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=6112


题目大意:

  给定日期,求下一个同月同日且为同星期的年份。

题目思路:

  【公式】

  利用蔡勒公式(见代码)求解某一具体日期的星期,往后枚举即可。(注意闰年2月29日)

/****************************************************

Author : Coolxxx
Copyright 2017 by Coolxxx. All rights reserved.
BLOG : http://blog.csdn.net/u010568270 
****************************************************/
#include<bits/stdc++.h>
#pragma comment(linker,"/STACK:1024000000,1024000000")
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define mem(a,b) memset(a,b,sizeof(a))
const double EPS=0.00001;
const int J=10;
const int MOD=100000007;
const int MAX=0x7f7f7f7f;
const double PI=3.14159265358979323;
const int N=104;
const int M=1004;
using namespace std;
typedef long long LL;
double anss;
LL aans;
int cas,cass;
int n,m,lll,ans;
int week(int year,int month,int day)
{
if(month<3)
{
year-=1;
month+=12;
}
int c=int(year/100),y=year-100*c;
int w=int(c/4)-2*c+y+int(y/4)+(26*(month+1)/10)+day-1;
w=(w%7+7)%7;
return w;
}
int week1(int y,int m,int d)
{
if(m==1) m=13,y--;
if(m==2) m=14,y--;
int week=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
return week;
}
int main()
{
#ifndef ONLINE_JUDGE
//	freopen("1.txt","r",stdin);
//	freopen("2.txt","w",stdout);
#endif
int i,j,k;
int x,y,z;
//	for(scanf("%d",&cass);cass;cass--)
for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
//	while(~scanf("%d",&n))
{
int year,month,day;
scanf("%d-%d-%d",&year,&month,&day);
x=week(year,month,day);
if(month==2 && day==29)
z=4;
else z=1;
for(i=year+z;i<10000;i+=z)
{
if(z==4 && !((i%4==0 && i%100!=0) || (i%400==0)))
continue;
y=week(i,month,day);
if(y==x)break;
}
printf("%d\n",i);
}
return 0;
}
/*
//

//
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐