HDU 1079 简单博弈

判断下一步能否到达必胜态,如果可以当前状态就是必败态,否则当前状态记为必胜态

 

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <iostream>

 4 using namespace std;

 5 bool p[115][13][40];

 6 int month[13] = {0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};

 7 

 8 struct Date{

 9     int y , m , d;

10     Date(int y=0 , int m=0 , int d=0):y(y),m(m),d(d){}

11 };

12 

13 bool run(int y)

14 {

15     return y%400 == 0 || (y%4 == 0 && y%100 != 0);

16 }

17 

18 bool ok(int y , int m , int d)

19 {

20     if(run(y)) month[2]=29;

21     bool flag;

22     if(d > month[m]) flag = false;

23     else flag = true;

24     month[2] = 28;

25     return flag;

26 }

27 

28 Date getLastDay(int y , int m , int d)

29 {

30     Date tmp;

31     tmp.y = y , tmp.m = m , tmp.d =d;

32     if(run(y)) month[2]=29;

33     if(d == 1){

34         if(m == 1){

35             tmp.y--;

36             tmp.d=31 , tmp.m =12;

37         }else{

38             tmp.m--;

39             tmp.d = month[tmp.m];

40         }

41     }

42     else tmp.d--;

43     month[2] = 28;

44     return tmp;

45 }

46 

47 Date get_next_month(int y , int m , int d)

48 {

49     Date tmp;

50     tmp.y = y , tmp.m = m , tmp.d =d;

51     if(m == 12) tmp.m=1 , tmp.y+=1;

52     else tmp.m+=1;

53     return tmp;

54 }

55 

56 void init()

57 {

58     memset(p , 0 , sizeof(p));

59     p[101][11][4] = true;

60     Date cur = Date(2001 , 11 , 4);

61     while(1){

62         Date la = getLastDay(cur.y , cur.m , cur.d);

63 

64         Date next_month = get_next_month(la.y , la.m , la.d);

65         bool p1 = p[cur.y-1900][cur.m][cur.d];

66         bool p2 = false;

67 

68         if(ok(next_month.y , next_month.m , next_month.d))

69             p2 = p[next_month.y-1900][next_month.m][next_month.d];

70         if(p1 || p2) p[la.y-1900][la.m][la.d] = false;

71         else p[la.y-1900][la.m][la.d] = true;

72 

73         cur.y = la.y , cur.m = la.m , cur.d = la.d;

74         if(cur.y == 1900 && cur.m == 1 && cur.d == 1) break;

75     }

76 }

77 

78 int main()

79 {

80   //  freopen("a.in" , "r" , stdin);

81     int T;

82     scanf("%d" , &T);

83     init();

84 

85     while(T--)

86     {

87         int y , m ,d;

88         scanf("%d%d%d" , &y , &m , &d);

89 

90         if(p[y-1900][m][d]) puts("NO");

91         else puts("YES");

92     }

93     return 0;

94 }

 

你可能感兴趣的:(HDU)