poj1082-Calendar Game-博弈/sg

时间:2022-10-03 18:06:51

sg大法好 无脑sg即可,不用去找规律了。

 /*--------------------------------------------------------------------------------------*/

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map> //debug function for a N*M array
#define debug_map(N,M,G) printf("\n");for(int i=0;i<(N);i++)\
{for(int j=;j<(M);j++){\
printf("%d",G[i][j]);}printf("\n");}
//debug function for int,float,double,etc.
#define debug_var(X) cout<<#X"="<<X<<endl;
#define LL long long
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-;
/*--------------------------------------------------------------------------------------*/
using namespace std; int N,M,T;
int days[] = {,,,,,,,,,,,,};
int mem[][][]; bool leap(int yy)
{
return ((yy%== && yy%!=)|| (yy%== && yy%==));
} int sg(int yy,int mm,int dd,int dep)
{
//for(int i=0;i<dep;i++) printf("-");
//printf("%d:%d:%d\n",yy,mm,dd); if(yy== && mm== && dd==) return ;
if(yy > || (yy==&&mm>) || (yy==&&mm==&&dd>)) return -;
if(mem[yy][mm][dd] != -) return mem[yy][mm][dd];
set<int> st;
//+1 month
if(mm== && dd== && leap(yy)) st.insert(sg(yy,,,dep+));
else if(days[(mm== ? : mm+) ] >= dd ) st.insert(sg(mm==?yy+:yy,mm==?:mm+,dd,dep+) ); //+1 day
if(mm == && dd == ) st.insert(sg(yy+,,,dep+));
else if(mm== && dd == && leap(yy)) st.insert(sg(yy,,,dep+));
else if(mm== && dd == && !leap(yy)) st.insert(sg(yy,,,dep+));
else if(dd == days[mm]) st.insert(sg(yy,mm+,,dep+));
else st.insert(sg(yy,mm,dd+,dep+)); int g = ;
while(st.find(g) != st.end()) g++;
return mem[yy][mm][dd] = g;
} int main()
{
//freopen("output.txt","w",stdout);
scanf("%d",&T);
memset(mem,-,sizeof mem);
while(T--)
{
int yy,mm,dd;
scanf("%d%d%d",&yy,&mm,&dd);
printf("%s\n",sg(yy,mm,dd,)?"YES":"NO");
}
}