poj1082-Calendar Game-博弈/sg

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("\n");for(int i=0;i<(N);i++)\
19 {for(int j=0;j<(M);j++){\
20 printf("%d",G[i][j]);}printf("\n");}
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\n",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\n",sg(yy,mm,dd,0)?"YES":"NO");
74     }
75 }

 

转载于:https://www.cnblogs.com/helica/p/5781058.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值