# hdu4753

很容易看出来，总共才16个点、24条边。用一个int类型数字就可以描述这个图了，按照16点的关系可以找出已确定的那些边。然后就是很简单的DP了。

 1 #include <iostream>
2 #include <cstring>
3 #include <cstdio>
4 #include <algorithm>
5 using namespace std;
6 int jb[9]={ (1<<16)|(1<<13)|(1<<4)|(1<<1),
7              (1<<19)|(1<<16)|(1<<5)|(1<<2),
8              (1<<22)|(1<<19)|(1<<6)|(1<<3),
9              (1<<17)|(1<<14)|(1<<7)|(1<<4),
10              (1<<20)|(1<<17)|(1<<8)|(1<<5),
11              (1<<23)|(1<<20)|(1<<9)|(1<<6),
12              (1<<18)|(1<<15)|(1<<10)|(1<<7),
13              (1<<21)|(1<<18)|(1<<11)|(1<<8),
14              (1<<24)|(1<<21)|(1<<12)|(1<<9)
15 };
16 int d[20][20];
17 void gao(){
18     d[1][2]=1,d[2][3]=2,d[3][4]=3;
19     d[5][6]=4,d[6][7]=5,d[7][8]=6;
20     d[9][10]=7,d[10][11]=8,d[11][12]=9;
21     d[13][14]=10,d[14][15]=11,d[15][16]=12;
22     d[1][5]=13,d[5][9]=14,d[9][13]=15;
23     d[2][6]=16,d[6][10]=17,d[10][14]=18;
24     d[3][7]=19,d[7][11]=20,d[11][15]=21;
25     d[4][8]=22,d[8][12]=23,d[12][16]=24;
26 }
27 int zhuge(int x,int y){
28     if(x>y) swap(x,y);
29     return d[x][y];
30 }
31 int score[2],lastc;
32 int get_lc(int em){
33     int lc=0;
34     for(int i=0;i<9;i++)
35     if((em&jb[i])==jb[i])
36         lc++;
37     return lc;
38 }
39 int DP(int sc[2],int em,int id,int run,int lastc){
40     if(run > 24) {
41       if(sc[id]>sc[1-id]) return 1;
42       return 0;
43     }
44     for(int i=1;i<=24;i++)
45     if(!((1<<i)&em)){
46         int n_sc[2]={sc[0],sc[1]};
47         int n_em=em|(1<<i),lc=get_lc(n_em);
48         n_sc[id] += lc-lastc;
49         if(!DP(n_sc,n_em,1-id,run+1,lc)) return 1;
50     }
51     return 0;
52 }
53 int main()
54 {
55     gao();
56     int cases; cin>>cases;
57     for(int cas=1;cas<=cases;cas++){
58         score[0]=score[1]=0;
59         lastc=0;
60         int id=0,em=0;
61         int pl,run=1; cin>>pl;
62         while(run<=pl){
63             int x,y,e,lc;
64             scanf("%d%d",&x,&y); e=zhuge(x,y);
65             em |= 1<<e;   lc = get_lc(em);
66             score[id] += lc-lastc; lastc=lc;
67             id=1-id;
68             run++;
69         }
70         int status=DP(score,em,id,run,lastc);
71         printf("Case #%d: ",cas);
72         if((id==0&&status) || (id==1&&!status)) printf("Tom200\n");
73         else printf("Jerry404\n");
74     }
75     return 0;
76 }
View Code

posted on 2013-09-21 23:31 风言风语^-^ 阅读(...) 评论(...) 编辑 收藏