|
题目名称 |
日历游戏 |
最大公约数 |
密码 |
|
英文代号 |
calendar |
gcd |
pasuwado |
|
输入文件名 |
calendar.in |
gcd.in |
pasuwado.in |
|
输出文件名 |
calendar.out |
gcd.out |
pasuwado.out |
|
时限 |
1秒 |
1秒 |
1秒 |
|
空间限制 |
128M |
256M |
256M |
|
测试点数目 |
20 |
10 |
10 |
|
测试点分值 |
5 |
10 |
10 |
|
是否有部分分 |
无 |
无 |
无 |
|
附加文件 |
无 |
无 |
无 |
|
题目类型 |
传统 |
传统 |
传统 |
|
是否有SPJ |
无 |
无 |
无 |
注意:最终测试时,所有编译命令均不打开任何优化开关。
请独立完成题目,不要讨论,不得使用搜索引擎。
- 1. 日历游戏
【问题描述】
moreD和moreD的宠物CD正在玩一个日历游戏,开始时,他们从1900年1月1日到2012年12月22日(你懂的……)选一个日期开始,依次按照如下规则之一向后跳日期:
- 跳到日历上的下一天。
- 跳到日历上的下个月的同一天(如果不存在,则不能这么做)。
要是谁正好到达2012年12月22日那么他就赢了,如果到达这天之后的日期那他就输了——原因你也懂的。
每次都是moreD先走的。
现在,给你一个日期,请问moreD一定能赢吗?
【输入】
输入共T行,每行三个整数,Y、M、D,分别表示年、月、日。日期在1900年1月1日到2012年12月22日之间(包含两端)。
T并不在输入数据当中。
【输出】
要是moreD一定能赢,输出一行YES,否则输出NO。
【输入输出样例一】
|
calendar.in |
calendar.out |
|
2012 12 20 |
NO |
1956 3 26
【输入输出样例二】
|
calendar.in |
calendar.out |
|
2012 12 21 |
YES |
【数据描述】
对于50%的数据,是1949年1月1日后的日期。 T <= 5
对于100%的数据,是1900年1月1日后的日期。T <= 10
/* 一看题目是博弈就懵了.... 其实可以转化成好理解的 每个状态获胜的条件是后面的某一个状态不合法 而失败则是后面的每个状态都合法 然后搜一下就好了 */ #include<iostream> #include<cstdio> #include<cstring> using namespace std; int n,f[2015][15][35]; int M[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int Judge(int x){ return x%400==0||(x%4==0&&x%100); } void Get1(int &a,int &b,int &c){ int sum=M[b]; if(b==2)sum+=Judge(a); if(c>sum){ c=1;b++; } if(b>12){ b=1;a++; } } void Get2(int &a,int &b,int &c){ if(b>12){ b=1;a++; } int sum=M[b]; if(b==2)sum+=Judge(a); if(c>sum){ a=2013;return; } } int Canot(int a,int b,int c){ if(a==2012&&b==12&&c>22)return 1; if(a>2012)return 1; return 0; } int Dfs(int a,int b,int c){ if(a==2012&&b==12&&c==22)return f[a][b][c]=0; if(f[a][b][c]!=-1)return f[a][b][c]; if(Canot(a,b,c))return f[a][b][c]=1; int x,y,z; x=a,y=b,z=c; z++;Get1(x,y,z); if(!Dfs(x,y,z))return f[a][b][c]=1; x=a,y=b,z=c; y++;Get2(x,y,z); if(!Dfs(x,y,z))return f[a][b][c]=1; return f[a][b][c]=0; } int main() { freopen("calendar.in","r",stdin); freopen("calendar.out","w",stdout); int a,b,c; memset(f,-1,sizeof(f)); while(~scanf("%d%d%d",&a,&b,&c)){ if(Dfs(a,b,c))printf("YES\n"); else printf("NO\n"); } return 0; }