http://acm.pku.edu.cn/JudgeOnline/problem?id=1082
Код:
#include <iostream> using namespace std; int monthd[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool flag[110][13][32]; bool re, ex; void repire(int *YY, int *MM, int *DD){ if(*MM == 2){ if(*YY % 400 == 0 || (*YY % 4 == 0 && *YY % 100 != 0)) monthd[2] = 29; else monthd[2] = 28; } if(*DD > monthd[*MM]){ (*MM)++; if(*MM > 12){ (*YY)++; *MM = 1; } *DD = 1; } else if(*DD <= 0){ (*MM)--; if(*MM <= 0){ (*YY)--; *MM = 12; } if(*MM == 2){ if(*YY % 400 == 0 || (*YY % 4 == 0 && *YY % 100 != 0)) monthd[2] = 29; else monthd[2] = 28; } *DD = monthd[*MM]; } } bool right(int *YY, int *MM, int *DD){ if(*YY > 2001) return false; if(*YY < 2001) return true; else if(*YY == 2001){ if(*MM > 11) return false; else if(*MM < 11) return true; else if(*MM == 11){ if(*DD <= 4) return true; else return false; } } } bool exist(int *YY, int *MM, int *DD){ if(*MM > 12) { *YY++; *MM = 1; return true; } if(*MM == 2){ if(*YY % 400 == 0 || (*YY % 4 == 0 && *YY % 100 != 0)) monthd[2] = 29; else monthd[2] = 28; } if(*DD > monthd[*MM]) return false; else return true; } int main() { void repire(int *YY, int *MM, int *DD); bool right(int *YY, int *MM, int *DD); bool exist(int *YY, int *MM, int *DD); int Y, M, D; int YY, MM, DD; flag[2001- 1900][11][4] = false; Y = 2001; M = 11; D = 3; while(Y >= 1900){ YY = Y; MM = M; DD = D + 1; repire(&YY, &MM, &DD); re = right(&YY, &MM, &DD); if(re == true) { if(flag[YY - 1900][MM][DD] == false){ flag[Y - 1900][M][D] = true; D--; repire(&Y, &M, &D); continue; } } YY = Y; MM = M + 1; DD = D; ex = exist(&YY, &MM, &DD); re = right(&YY, &MM, &DD); if(ex && re){ if(flag[YY - 1900][MM][DD] == false){ flag[Y - 1900][M][D] = true; D--; repire(&Y, &M, &D); continue; } } flag[Y - 1900][M][D] = false; D--; } int test; scanf("%d", &test); int y, m, d; while(test--){ scanf("%d%d%d", &y, &m, &d); if(flag[y - 1900][m][d])printf("YES\n"); else printf("NO\n"); } return 0; }