http://poj.org/problem?id=1082web
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 4820 | Accepted: 2273 |
Descriptiondom
Inputide
Outputthis
Sample Inputspa
3 2001 11 3 2001 11 2 2001 10 3
Sample Outputcode
YES NO NO
搜索+DP+博弈
1 #include <stdio.h> 2 #include <memory.h> 3 4 int isWin[102][13][32]; 5 int maxDay[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; 6 7 int judge(int y, int m, int d) 8 { 9 int win; 10 11 if(y > 101 || (y == 101 &&(m > 11 || (m == 11 && d > 4)))) return 1; 12 if(y == 101 && m == 11 && d == 4) return 0; 13 if(isWin[y][m][d] == -1) 14 { 15 win = 0; 16 if(m != 12) 17 { 18 if(d <= maxDay[m+1] || (d == 29 && m == 1 && (y % 4 ) == 0 && y != 0)) 19 if(judge(y, m+1, d) == 0) win = 1; 20 } 21 else if(judge(y+1, 1, d) == 0) win = 1; 22 23 if(win==0) 24 { 25 if(d < maxDay[m]) 26 win = 1-(judge(y, m, d+1)); 27 else if(m != 12) 28 win = 1-(judge(y, m+1, 1)); 29 else 30 win = 1-(judge(y+1, 1, 1)); 31 } 32 isWin[y][m][d] = win; 33 } 34 return (isWin[y][m][d]); 35 } 36 37 int main() 38 { 39 int iCase; 40 int m, d, y; 41 42 memset(isWin, 255, sizeof(isWin)); 43 scanf("%d", &iCase); 44 while(iCase--) 45 { 46 scanf("%d%d%d", &y, &m, &d); 47 if(judge(y - 1900, m, d) == 1) 48 printf("YES\n"); 49 else 50 printf("NO\n"); 51 } 52 return(0); 53 }