Calendar Game
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6052 Accepted Submission(s): 3618
A player wins the game when he/she exactly reaches the date of November 4, 2001. If a player moves to a date after November 4, 2001, he/she looses the game.
Write a program that decides whether, given an initial date, Adam, the first mover, has a winning strategy.
For this game, you need to identify leap years, where February has 29 days. In the Gregorian calendar, leap years occur in years exactly divisible by four. So, 1993, 1994, and 1995 are not leap years, while 1992 and 1996 are leap years. Additionally, the years ending with 00 are leap years only if they are divisible by 400. So, 1700, 1800, 1900, 2100, and 2200 are not leap years, while 1600, 2000, and 2400 are leap years.
2001 11 3
2001 11 2
2001 10 3
NO
NO
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
int date[][][];
bool judge(int x)
{
if(x%==&&x%!=){return false;}
else return x%==;
}
int dd[]={,,,,,,,,,,,,}; bool check1(int y,int m,int d)
{
m++;
if(m==){y++;m=;}
if(judge(y)){dd[]++;}
if(d>dd[m]){
if(judge(y)){dd[]--;}
return true;
}
if(judge(y)){dd[]--;}
return date[y][m][d];
} bool check2(int y,int m,int d)
{
if(judge(y)){dd[]++;}
d++;
if(d>dd[m]){
m++;
if(m==){
y++;
m=;
}
d=;
}
if(judge(y)){dd[]--;} return date[y][m][d];
} void solve(int y,int m,int d)
{
bool flag1=check1(y,m,d);
bool flag2=check2(y,m,d);
if(!flag1||!flag2){date[y][m][d]=true;}
else date[y][m][d]=false;
} int main()
{
// ios::sync_with_stdio(false);
// freopen("in.txt","r",stdin); for(int i=;i<=;i++){
for(int j=;j<=;j++){
for(int k=;k<=;k++){
date[i][j][k]=true;
}
}
} int y,m,d;
y=,m=,d=;
date[y][m][d]=false;
while(true){
if(y==&&m==&&d==){break;}
d--;
if(d==){
m--;
if(m==){
y--;
m=;
}
d=dd[m];
if(judge(y)&&m==){d++;}
}
solve(y,m,d);
} int T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&y,&m,&d);
if(date[y][m][d]){printf("YES\n");}
else printf("NO\n");
} return ;
}
抱着比WA的心态交了一发,没想到居然A了,哈哈哈哈或或。