Input The input consists of T test cases. The number of test cases (T) is given in the first line of the input. Each test case is written in a line and corresponds to an initial date. The three integers in a line, YYYY MM DD, represent the date of the DD-th day of MM-th month in the year of YYYY. Remember that initial dates are randomly chosen from the interval between January 1, 1900 and November 4, 2001. Output Print exactly one line for each test case. The line should contain the answer "YES" or "NO" to the question of whether Adam has a winning strategy against Eve. Since we have T test cases, your program should output totally T lines of "YES" or "NO". Sample Input 3 2001 11 3 2001 11 2 2001 10 3 Sample Output YES NO NO 题目分析:这道题我是先运用P/N法分析了一下,显然2001//11/4日是一个必败点(P点),往前2001//11/3和//2001//10/4是一个必胜点(N点)。这样的话我们就找到了这题的规律:每次从一个P点开始枚举,找到它的N点,直到找完所有的点。这里我们用到了:如果一个节点的后续节点都是N点,该节点为P点,否则该节点为N。也即是说,只要有一个后续节点是P点,该节点就是N点。 做完这题我有想起了http://acm.hdu.edu.cn/showproblem.php?pid=1847这道题,当时我分析这道题(见这里http://blog.csdn.net/zhangxiang0125/archive/2011/02/08/6174639.aspx)的时候用的是求sg值法。我说用P/N分析更简单,现在想想其实不然。因为这题说两位选手每次拿牌是2^i次。如果数据比较刁钻。用P/N分析很难一下子找出规律(在ACM那样的赛场上应该寻求尽快解决)。而求sg值得话,只要你掌握了公式或这有个很不错的模版,那么解决题目就可在瞬间秒杀。当然我只是菜鸟。。只是做题的一点小心得、还有待实践证明。望指正! 下面是1079的代码: #include<cstdio> #include<algorithm> using namespace std; int later_y,later_m,later_d; int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool sg[2002][13][35]; int is_leap(int x) { if(x%4==0 || (x%100==0&&x%400==0)) return 1; return 0; } int is_legal(int y,int m,int d) { if(y==2001) { if(m>11 ||(m==11&&d>4)) return 0; } if(m==2) { if(is_leap(y)) { if(d>29) return 0; else return 1; } } if(month[m]>=d) return 1; else return 0; } void mex() { memset(sg,false,sizeof(sg)); for(int i=2001;i>=1900;i--) { for(int j=12;j>0;j--) { for(int d=31;d>0;d--) { if(is_legal(i,j,d)) { if(!sg[i][j][d]) { later_y=i; later_m=j; later_d=d-1; if(later_d==0) { later_m--; if(later_m==0) { later_y--; later_m=12; } if(is_leap(later_y) && later_m==2) later_d=month[later_m]+1; else later_d=month[later_m]; } sg[later_y][later_m][later_d]=true; later_y=i; later_m=j-1; later_d=d; if(later_m==0) { later_y--; later_m=12; } if(is_legal(later_y,later_m,later_d)) sg[later_y][later_m][later_d]=true; } } } } } } int main() { freopen("game.in","r",stdin); freopen("game.out","w",stdout); int ncase,curyear,curmonth,curday; mex(); scanf("%d",&ncase); while(ncase--) { scanf("%d%d%d",&curyear,&curmonth,&curday); if(sg[curyear][curmonth][curday]) printf("YES/n"); else printf("NO/n"); } return 0; }