sg大法好 无脑sg即可,不用去找规律了。
1 /*--------------------------------------------------------------------------------------*/ 2 3 #include <algorithm> 4 #include <iostream> 5 #include <cstring> 6 #include <ctype.h> 7 #include <cstdlib> 8 #include <cstdio> 9 #include <vector> 10 #include <string> 11 #include <queue> 12 #include <stack> 13 #include <cmath> 14 #include <set> 15 #include <map> 16 17 //debug function for a N*M array 18 #define debug_map(N,M,G) printf(" ");for(int i=0;i<(N);i++) 19 {for(int j=0;j<(M);j++){ 20 printf("%d",G[i][j]);}printf(" ");} 21 //debug function for int,float,double,etc. 22 #define debug_var(X) cout<<#X"="<<X<<endl; 23 #define LL long long 24 const int INF = 0x3f3f3f3f; 25 const LL LLINF = 0x3f3f3f3f3f3f3f3f; 26 const double eps = 1e-8; 27 /*--------------------------------------------------------------------------------------*/ 28 using namespace std; 29 30 int N,M,T; 31 int days[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; 32 int mem[2100][15][40]; 33 34 bool leap(int yy) 35 { 36 return ((yy%4==0 && yy%100!=0)|| (yy%100==0 && yy%400==0)); 37 } 38 39 int sg(int yy,int mm,int dd,int dep) 40 { 41 //for(int i=0;i<dep;i++) printf("-"); 42 //printf("%d:%d:%d ",yy,mm,dd); 43 44 if(yy==2001 && mm==11 && dd==4) return 0; 45 if(yy > 2001 || (yy==2001&&mm>11) || (yy==2001&&mm==11&&dd>4)) return -1; 46 if(mem[yy][mm][dd] != -1) return mem[yy][mm][dd]; 47 set<int> st; 48 //+1 month 49 if(mm==1 && dd==28 && leap(yy)) st.insert(sg(yy,2,28,dep+1)); 50 else if(days[(mm==12 ? 1 : mm+1) ] >= dd ) st.insert(sg(mm==12?yy+1:yy,mm==12?1:mm+1,dd,dep+1) ); 51 52 //+1 day 53 if(mm == 12 && dd == 31) st.insert(sg(yy+1,1,1,dep+1)); 54 else if(mm==2 && dd == 27 && leap(yy)) st.insert(sg(yy,2,28,dep+1)); 55 else if(mm==2 && dd == 27 && !leap(yy)) st.insert(sg(yy,3,1,dep+1)); 56 else if(dd == days[mm]) st.insert(sg(yy,mm+1,1,dep+1)); 57 else st.insert(sg(yy,mm,dd+1,dep+1)); 58 59 int g = 0; 60 while(st.find(g) != st.end()) g++; 61 return mem[yy][mm][dd] = g; 62 } 63 64 int main() 65 { 66 //freopen("output.txt","w",stdout); 67 scanf("%d",&T); 68 memset(mem,-1,sizeof mem); 69 while(T--) 70 { 71 int yy,mm,dd; 72 scanf("%d%d%d",&yy,&mm,&dd); 73 printf("%s ",sg(yy,mm,dd,0)?"YES":"NO"); 74 } 75 }