hdu6122今夕何夕数学公式(2017"百度之星"程序设计大赛-初赛(a))

Coolxxx Coolxxx     2022-09-14     609

关键词:

今夕何夕

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
 

 

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日)

  

  

技术分享
 1 /****************************************************
 2 
 3     Author : Coolxxx
 4     Copyright 2017 by Coolxxx. All rights reserved.
 5     BLOG : http://blog.csdn.net/u010568270
 6 
 7 ****************************************************/
 8 #include<bits/stdc++.h>
 9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 const double EPS=0.00001;
15 const int J=10;
16 const int MOD=100000007;
17 const int MAX=0x7f7f7f7f;
18 const double PI=3.14159265358979323;
19 const int N=104;
20 const int M=1004;
21 using namespace std;
22 typedef long long LL;
23 double anss;
24 LL aans;
25 int cas,cass;
26 int n,m,lll,ans;
27 int week(int year,int month,int day)
28 {
29     if(month<3)
30     {
31         year-=1;
32         month+=12;
33     }
34     int c=int(year/100),y=year-100*c;
35     int w=int(c/4)-2*c+y+int(y/4)+(26*(month+1)/10)+day-1;
36     w=(w%7+7)%7;
37     return w;
38 }
39 int week1(int y,int m,int d)
40 {
41     if(m==1) m=13,y--;
42     if(m==2) m=14,y--;
43     int week=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
44     return week;
45 }
46 int main()
47 {
48     #ifndef ONLINE_JUDGE
49 //    freopen("1.txt","r",stdin);
50 //    freopen("2.txt","w",stdout);
51     #endif
52     int i,j,k;
53     int x,y,z;
54 //    for(scanf("%d",&cass);cass;cass--)
55     for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
56 //    while(~scanf("%d",&n))
57     {
58         int year,month,day;
59         scanf("%d-%d-%d",&year,&month,&day);
60         x=week(year,month,day);
61         if(month==2 && day==29)
62             z=4;
63         else z=1;
64         for(i=year+z;i<10000;i+=z)
65         {
66             if(z==4 && !((i%4==0 && i%100!=0) || (i%400==0)))
67                 continue;
68             y=week(i,month,day);
69             if(y==x)break;
70         }
71         printf("%d
",i);
72     }
73     return 0;
74 }
75 /*
76 //
77 
78 //
79 */
View Code

 






















zeller公式计算星期几hdu6112今夕何夕

acm.hdu.edu.cn/showproblem.php?pid=6112【思路】公式计算即可,注意特判2月29号Zeller公式里,计算出的week不能直接模7,要保证week是正数【AC】1#include<iostream>2#include<cstdio>3#include<cstring>4#include<string>5#inclu 查看详情

hdu6112今夕何夕数论

今夕何夕Description今天是2017年8月6日,农历闰六月十五。小度独自凭栏,望着一轮圆月,发出了“今夕何夕,见此良人”的寂寞感慨。为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年里的同一个日子,和今天的星... 查看详情

hdu6112今夕何夕

今夕何夕TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):690    AcceptedSubmission(s):211ProblemDescription今天是2017年8月6日 查看详情

hdu6112今夕何夕(模拟)

今夕何夕TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):484    AcceptedSubmission(s):151ProblemDescription今天是2017年8月6日 查看详情

hdu6108小c的倍数问题数学(2017"百度之星"程序设计大赛-初赛(a))

小C的倍数问题TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):481    AcceptedSubmission(s):278ProblemDescription根据小学数学的知识 查看详情

hdu6112今夕何夕(这也要写??)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6112题目大意:给你一个合法的年月日,问下次同样是这个月日,星期一样的最早是哪年?题目保证不超过四位数。解题思路:讲道理真的需要吗?过一年+365天,如果是闰年+366天,对7... 查看详情

2016"百度之星"-初赛(astarround2a)--hdu5690|数学转化+快速幂

  SampleInput313521351359969 SampleOutputCase#1:NoCase#2:YesCase#3:YesHint对于第一组测试数据:111mod5=1,公式不成立,所以答案是”No”,而第二组测试数据中满足如上公式,所以答案是“Yes”。 解:m个x组成的数可以表示为x*(1+1... 查看详情

2017"百度之星"程序设计大赛-复赛1003&&hdu6146pokémongo数学,递推,dp

PokémonGOTimeLimit:3000/1500MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):171    AcceptedSubmission(s):104ProblemDescription 查看详情

hdu3117fibonaccinumbers数学

http://acm.hdu.edu.cn/showproblem.php?pid=3117fib是有一个数学公式的。这里的是标准的fib公式那么fib=1/sqrt(5)*((1+sqrt(5)/2)^n-((1-sqrt(5))/2)^n)=1/sqrt(5)*(A^n-B^n)那么,求后4位可以直接矩阵快速幂。不能用上面公式的快速幂取模,因为存在精度误差... 查看详情

hdu4059:thebossonmars(数学公式+容斥原理)

http://acm.hdu.edu.cn/showproblem.php?pid=4059题意:给出一个n,求1~n里面与n互质的数的四次方的和是多少。思路;不知道1~n的每个数的四次方的求和公式。看的是这篇:http://blog.csdn.net/acm_cxlove/article/details/7434864。求和公式:(1^4+2^4+…... 查看详情

hdu6088rikkawithrock-paper-scissors(2017多校第五场1004)组合数学+数论+模意义下的fft

题目链接首先利用组合数学知识,枚举两人的总胜场数容易得到这还不是卷积的形式,直接搞的话复杂度大概是O(n^2)的,肯定会TLE。但似乎和卷积有点像?想半天没想出来。。多谢Q巨提醒,才知道可以用下面这个公式进行转化&n... 查看详情

2017百度之星初赛a今夕何夕

今夕何夕  Accepts:1345  Submissions:5533 TimeLimit:2000/1000MS(Java/Others)  MemoryLimit:32768/32768K(Java/Others)ProblemDescription今天是2017年8月6日,农历闰六月十五。小度独自凭栏,望着一轮圆月,发出 查看详情

百度之星2017初赛a-1005-今夕何夕

今夕何夕TimeLimit:2000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):719    AcceptedSubmission(s):228ProblemDescription今天是2017年8月6日 查看详情

hdu1060[leftmostdigit]数学

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060题目大意:求N^N的最高位数字。关键思想:换底公式使结果变为10^(N*log10(N)),再除以10^(digits-1)就OK了。代码如下://运用换底公式避免幂运算,取整处理。#include<iostream>#include<... 查看详情

hdu3104combinationlock(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3104ProblemDescriptionAcombinationlockconsistsofacirculardial,whichcanbeturned(clockwiseorcounterclockwise)andisembeddedintothe"fixed"partofthe 查看详情

百度之星初赛(a)——t5

今夕何夕ProblemDescription今天是2017年8月6日,农历闰六月十五。小度独自凭栏,望着一轮圆月,发出了“今夕何夕,见此良人”的寂寞感慨。为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年里的同一个日子,和今天... 查看详情

2017多校第10场hdu6172arraychallenge猜公式,矩阵幂

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6172题意:如题。解法: #include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;constLLmod=1e9+7;structMatrix{LLa[3][3];voidset1(){memset(a,0,sizeof( 查看详情

数学符号数学运算符号

有什么输入发可以打数学符号的?还有什么软件可以打出数学的式子的?参考技术A在OfficeWord里面就可以输入数学公式,不过不太好用。要输入数学公式的话,这里推荐MathType数学公式编辑器。不过提醒一下,打印的时候如果打... 查看详情