HDOJ Monthly Contest – 2010.04.04

1001  Connect the Cities

 

最小生成树,先构造已经存在的路,然后再建路 ,1y


1008  San Guo Sha

背景是三国杀游戏,由于游戏的规则没有完全懂,所以一直wa

参考了别人的代码,就ac了


 

code
   
     
1 #include < stdio.h >
2 #include < string .h >
3   #define NL 205
4
5   struct P {
6 int id;
7 int add; // 附加得分
8   bool lv; // alive
9   bool nj_zg; // 内奸与主公单挑结果
10   };
11
12 P py[NL];
13   int exe[NL][ 2 ];
14   int cnt[ 5 ]; // 1主公,2忠臣,3内奸,4反贼
15   int win;
16
17 bool check()
18 {
19 if (cnt[ 1 ] && cnt[ 3 ] == 0 && cnt[ 4 ] == 0 ) {
20 win = 1 ; // 主公忠臣赢
21 return 1 ;
22 } else if (cnt[ 1 ] == 0 ) {
23 if (cnt[ 2 ] == 0 && cnt[ 4 ] == 0 && cnt[ 3 ] == 1 ) {
24 win = 3 ; // 内奸赢
25 } else {
26 win = 2 ; // 反贼赢
27 }
28 return 1 ;
29 }
30 return 0 ;
31 }
32
33 int main()
34 {
35 int T;
36
37 scanf( " %d " , & T);
38 while (T -- ) {
39 int n, m;
40 int i;
41
42 for (i = 1 ; i <= 4 ; i ++ )
43 cnt[i] = 0 ;
44 memset(py, 0 , sizeof (py));
45 memset(exe, 0 , sizeof (exe));
46 scanf( " %d%d " , & n, & m);
47 for (i = 0 ; i < n; i ++ ) {
48 char s[ 10 ];
49 scanf( " %s " , s);
50 switch (s[ 1 ]) {
51 case ' G ' :
52 cnt[ 1 ] ++ ;
53 py[i].id = 1 ;
54 break ;
55 case ' C ' :
56 cnt[ 2 ] ++ ;
57 py[i].id = 2 ;
58 break ;
59 case ' J ' :
60 cnt[ 3 ] ++ ;
61 py[i].id = 3 ;
62 break ;
63 case ' Z ' :
64 cnt[ 4 ] ++ ;
65 py[i].id = 4 ;
66 break ;
67 }
68 }
69 for (i = 0 ; i < m; i ++ ) {
70 scanf( " %d%d " , & exe[i][ 0 ], & exe[i][ 1 ]);
71 }
72 win = 0 ;
73 for (i = 0 ; i < m; i ++ ) {
74 int a, b, i1, i2;
75 a = exe[i][ 0 ]; // a kill b
76 b = exe[i][ 1 ];
77 i1 = py[a].id;
78 i2 = py[b].id;
79 py[b].lv = 1 ; // 1 表示死亡
80 // NJ vs ZG in the last
81 if (i1 == 1 && i2 == 3
82 && cnt[ 1 ] == 1 && cnt[ 2 ] == 0 && cnt[ 3 ] == 1 && cnt[ 4 ] == 0 ) {
83 py[b].nj_zg = 1 ; // 得到单挑得分
84 }
85 if ((i1 == 1 || i1 == 2 )
86 && (i2 == 3 || i2 == 4 ))
87 py[a].add ++ ;
88 if (i1 == 4 ) {
89 if (i2 == 2 || i2 == 3 )
90 py[a].add ++ ;
91 else if (i2 == 1 )
92 py[a].add += 2 ;
93 }
94 cnt[i2] -- ; // 人数减一
95 if (check()) break ;
96 }
97 if (win == 1 ) {
98 for (i = 0 ; i < n; i ++ ) {
99 if (i != 0 ) printf( " " );
100 switch (py[i].id) {
101 case 1 :
102 printf( " %d " , 4 + cnt[ 2 ] * 2 + py[i].add);
103 break ;
104 case 2 :
105 printf( " %d " , 5 + cnt[ 2 ] + py[i].add);
106 break ;
107 case 4 :
108 printf( " 0 " );
109 break ;
110 case 3 :
111 if (py[i].nj_zg)
112 printf( " %d " , n);
113 else
114 printf( " 0 " );
115 break ;
116 }
117 }
118 } else if (win == 2 ) {
119 for (i = 0 ; i < n; i ++ ) {
120 if (i != 0 ) printf( " " );
121 switch (py[i].id) {
122 case 1 :
123 case 2 :
124 printf( " 0 " );
125 break ;
126 case 4 :
127 printf( " %d " , cnt[ 4 ] * 3 + py[i].add);
128 break ;
129 case 3 :
130 if ( ! py[i].lv) // 存活的内奸
131 printf( " 1 " );
132 else
133 printf( " 0 " );
134 break ;
135 }
136 }
137 } else if (win == 3 ){
138 for (i = 0 ; i < n; i ++ ) {
139 if (i != 0 ) printf( " " );
140 switch (py[i].id) {
141 case 1 :
142 printf( " 1 " );
143 break ;
144 case 2 :
145 case 4 :
146 printf( " 0 " );
147 break ;
148 case 3 :
149 if ( ! py[i].lv)
150 printf( " %d " , 4 + n * 2 );
151 else
152 printf( " 0 " );
153 break ;
154 }
155 }
156 } else {
157 for (i = 0 ; i < n; i ++ ) {
158 if (i != 0 ) printf( " " );
159 printf( " 0 " );
160 }
161 }
162 printf( " \n " );
163 }
164 return 0 ;
165 }

 

 

你可能感兴趣的:(test)