HDU 4121

福州赛区最水的一道模拟题。。。。坑爹啊,各种细节没考虑到,导致WA了N多次后才得以AC。

这题就是判定当前的局面来说,对于黑方是否是死局。

还好黑方只有一个将。。。

红方也只有炮,马,车,帅。

思路很简单:考虑将能走四个方向。先判断这四个方向是否合理。

再对红方每个棋子能否扫描到这个点,可以的话就判断下一个方向。如果四个方向均被红方的棋子扫描到的话,就是死局。反之则不是。

这题还要注意一个细节就是有可能出现一种情况,黑方会吃掉你一个棋子。。。。。

  1 #include<iostream>
2 using namespace std;
3 char map[11][11];
4 const int dir[4][2] = {0,1,1,0,-1,0,0,-1};
5 int note[10][2];
6 int cnt;
7 int b_x, b_y;
8
9 bool law_G(int x, int y)
10 {
11 return x<=3 && x>=1 && y<=6 && y>=4;
12 }
13
14 bool deal_G(int x, int y, int n_x, int n_y)
15 {
16 if (n_y != y)return false;
17 while (--x >= 1){
18 if (x == n_x)return true;
19 if (map[x][y] == '.'){
20 continue;
21 } else{
22 return false;
23 }
24 }
25 return false;
26 }
27
28 bool check_right(int x, int y, int n_y)
29 {
30 for (int i(y+1); i<=9; ++i){
31 if (i == n_y)return true;
32 if (map[x][i] == '.'){
33 continue;
34 } else{
35 return false;
36 }
37 }
38 return false;
39 }
40
41 bool check_left(int x,int y, int n_y)
42 {
43 for (int i(y-1); i>=1; --i){
44 if (i == n_y)return true;
45 if (map[x][i] == '.'){
46 continue;
47 } else{
48 return false;
49 }
50 }
51 return false;
52 }
53
54 bool check_up(int x, int y,int n_x)
55 {
56 for (int i(x-1); i>=1; --i){
57 if (i == n_x)return true;
58 if (map[i][y] == '.'){
59 continue;
60 } else{
61 return false;
62 }
63 }
64 return false;
65 }
66
67 bool check_down(int x, int y, int n_x)
68 {
69 for (int i(x+1); i<=10; ++i){
70 if (i == n_x)return true;
71 if (map[i][y] == '.'){
72 continue;
73 } else{
74 return false;
75 }
76 }
77 return false;
78 }
79
80 bool deal_R(int x, int y, int n_x, int n_y)
81 {
82 if (x != n_x && y != n_y)return false;
83 if (x == n_x){
84 if (y < n_y){
85 if (check_right(x,y,n_y))return true;
86 return false;
87 } else{
88 if (check_left(x,y,n_y))return true;
89 return false;
90 }
91 } else{
92 if (x < n_x){
93 if (check_down(x,y,n_x))return true;
94 return false;
95 } else{
96 if (check_up(x,y,n_x))return true;
97 return false;
98 }
99 }
100 }
101
102 bool deal_C(int x, int y, int n_x, int n_y)
103 {
104 bool flag = false;
105 if (x != n_x && y != n_y)return false;
106 if (x == n_x){
107 if (y < n_y){
108 while (++y < n_y){
109 if (map[x][y] == '.'){
110 continue;
111 } else{
112 flag = true;
113 break;
114 }
115 }
116 if (flag){
117 if (check_right(x,y,n_y))return true;
118 }
119 } else{
120 while (--y > n_y){
121 if (map[x][y] == '.'){
122 continue;
123 } else{
124 flag = true;
125 break;
126 }
127 }
128 if (flag){
129 if (check_left(x,y,n_y))return true;
130 }
131 }
132 } else{
133 if (x < n_x){
134 while (++x < n_x){
135 if (map[x][y] == '.'){
136 continue;
137 } else{
138 flag = true;
139 break;
140 }
141 }
142 if (flag){
143 if (check_down(x,y,n_x))return true;
144 }
145 } else{
146 while (--x > n_x){
147 if (map[x][y] == '.'){
148 continue;
149 } else{
150 flag = true;
151 break;
152 }
153 }
154 if (flag){
155 if (check_up(x,y,n_x))return true;
156 }
157 }
158 }
159 return false;
160 }
161
162 bool deal_H(int x, int y, int n_x, int n_y){
163 if (x+2 == n_x && (y-1 == n_y || y+1 == n_y)){
164 if (map[x+1][y] == '.')return true;
165 return false;
166 } else{
167 if (x-2 == n_x && (y-1 == n_y || y+1 == n_y)){
168 if (map[x-1][y] == '.')return true;
169 return false;
170 } else{
171 if (y+2 == n_y && (x-1 == n_x || x+1 == n_x)){
172 if (map[x][y+1] == '.')return true;
173 return false;
174 } else{
175 if (y-2 == n_y && (x-1 == n_x || x+1 == n_x)){
176 if (map[x][y-1] == '.')return true;
177 return false;
178 }
179 }
180 }
181 }
182 return false;
183 }
184
185 bool dfs(int x, int y)
186 {
187 for (int i(0); i<4; ++i){
188 bool flag = false;
189 int now_x = x + dir[i][0];
190 int now_y = y + dir[i][1];
191 if (law_G(now_x,now_y)){
192 for (int j(0); j<cnt; ++j){
193 switch (map[note[j][0]][note[j][1]]){
194 case 'G':{
195 if (deal_G(note[j][0],note[j][1],now_x,now_y))flag = true;
196 break;
197 }
198 case 'R':{
199 if (deal_R(note[j][0],note[j][1],now_x,now_y))flag = true;
200 break;
201 }
202 case 'C':{
203 if (deal_C(note[j][0],note[j][1],now_x,now_y))flag = true;
204 break;
205 }
206 case 'H':{
207 if (deal_H(note[j][0],note[j][1],now_x,now_y))flag = true;
208 break;
209 }
210 }
211 if (flag)break;
212 }
213 if (!flag)return false;
214 }
215 }
216 return true;
217 }
218
219 int main()
220 {
221 int red_num;
222 while (cin>>red_num>>b_x>>b_y){
223 if (red_num == 0 && b_x == 0 && b_y == 0)break;
224 char temp;
225 memset(map,'.',sizeof(map));
226 cnt = 0;
227 int x, y;
228 while(red_num--){
229 cin>>temp>>x>>y;
230 switch(temp){
231 case 'G':{
232 map[x][y] = 'G';
233 break;
234 }
235 case 'C':{
236 map[x][y] = 'C';
237 break;
238 }
239 case 'H':{
240 map[x][y] = 'H';
241 break;
242 }
243 case 'R':{
244 map[x][y] = 'R';
245 break;
246 }
247 }
248 note[cnt][0] = x;
249 note[cnt++][1] = y;
250 }
251 if (dfs(b_x,b_y)){
252 cout<<"YES"<<endl;
253 } else{
254 cout<<"NO"<<endl;
255 }
256 }
257 return 0;
258 }

OK,完事。

posted on 2011-12-11 13:47  Dev-T  阅读(813)  评论(0编辑  收藏  举报