Subject to the effect:
Given a line with the rules of chess pieces on the board will only Black, red party has "delivered a check". Determining whether the required red side Black "checkmate".
Ideas:
1. To maintain a matrix showing the layout of pieces on the red side of the board;
2. Maintain a vector location storing the red side of the piece, for subsequent access;
3. Analog black process will take a step, for each will likely take the position of the black, black will determine whether it will be eaten. If all can go to the black position will be eaten, then the output YES . If there is a position of the black will escape, output NO.
Pit:
1. Black will come when the next may eat the red side.
2. While Black can not be eaten in the initial position, but now has to go turn Black, Black will have to take a step, you can not stay still. If all the place will be able to come to eat, Black still is to lose.
3. As we all know, the data on uDebug is likely to have a pit.
In particular, compared to the car and found the gun rules, and the gun can only skip a pawn on the route, but the car is not on the route checkers child (that can jump 0 pieces), in addition, the rules other portions are the same. Thus can the car and the same function package gun Chariot () , the only difference is 0 or 1 can jump pieces, see the specific calling codes, line 66 and line 71.
AC code is as follows (C ++)
1 #include <bits/stdc++.h> 2 #define N 11 3 #define mp(x,y) make_pair(x,y) 4 #define fi() first 5 #define se() second 6 using namespace std; 7 char mat[N][N]; 8 vector<pair<int,int> > rds; 9 const int mv[][2] = {{-1,0},{1,0},{0,1},{0,-1}}; 10 const int mv2[4][2][2] = { 11 {{-1,-1},{-1,1}}, 12 {{1,-1},{1,1}}, 13 {{-1,1},{1,1}}, 14 {{-1,-1},{1,-1}} 15 }; 16 . 17 // 18 // Analyzing car / gun (x, y) can be black (bx, by) eaten . 19 @ 20 is inline BOOL Chariot ( int BX, int by, int X, int Y, int CC) { 21 is int CNT = 0 ; 22 is IF (X == BX) { 23 is for ( int I = min (by, Y) + . 1 ; I <max (by, Y); ++ I) { 24 IF (MAT [X] [I] =! 0 ) { 25 ++ CNT; 26 } 27 } 28 if(cnt==cc) return false; 29 } else if (y==by) { 30 for(int i=min(bx,x)+1; i<max(bx,x); ++i) { 31 if(mat[i][y] != 0) { 32 ++cnt; 33 } 34 } 35 if(cnt==cc) return false; 36 } 37 return to true ; 38 is } 39 40 inline BOOL inbnd ( int R & lt, int C) { 41 is return (R & lt <! . 1 || R & lt> 10 || C < . 1 || C> . 9 ); 42 is } 43 is 44 is // 45 // determining whether the hazard on the black (BX, by) 46 is // 47 BOOL Judge ( int BX, int by) { 48 for (size_t I = 0 ; I <rds.size (); ++ I) { 49 int x = rds[i].fi(); 50 int y = rds[i].se(); 51 if(x==bx&&y==by) continue; 52 switch(mat[x][y]) { 53 case 'G': 54 if(y==by) { 55 int i; 56 for(i=bx+1; i<x; ++i) { 57 if(mat[i][y] != 0) { 58 break; 59 } 60 } 61 if(i==x) return false; 62 } 63 break; 64 case 'R': 65 if(x==bx || y==by) { 66 if(!chariot(bx,by,x,y, 0)) return false; 67 } 68 break; 69 case 'C': 70 { 71 if(!chariot(bx,by,x,y, 1)) return false; 72 } 73 break; 74 case 'H': 75 for(int i=0;i<4;++i) { 76 int nx1=x+mv[i][0], ny1=y+mv[i][1]; 77 if(inbnd(nx1,ny1) && mat[nx1][ny1]==0 && nx1!=bx&&ny1!=by) { 78 for(int j=0;j<2;++j) { 79 intnxl + mv2 = NX2 [I] [J] [ 0 ], ny2 ny1 = mv2 + [I] [J] [ . 1 ]; 80 IF (BX && ny2 == == NX2 by) { 81 return to false ; 82 } 83 } 84 } 85 } 86 BREAK ; 87 } 88 } 89 return to true ; 90 } 91 is 92 // 93 // solving a single test 94 // 95 const char *solve(int bx, int by) { 96 for(int i=0;i<4;++i) { 97 int nx=bx+mv[i][0], ny=by+mv[i][1]; 98 if(nx<1||nx>3 || ny<4||ny>6) continue; 99 if(judge(nx,ny)) { 100 return "NO"; 101 } 102 } 103 return "YES"; 104 } 105 106 int main(void) { 107 ios::sync_with_stdio(false); 108 int n,xb,yb; 109 while((cin>>n>>xb>>yb) && (n&&xb&&yb)) { 110 memset(mat, 0, sizeof mat); 111 rds.clear(); 112 113 while(n--) { 114 char typ; int x,y; 115 cin>>typ>>x>>y; 116 mat[x][y] = typ; 117 rds.push_back(mp(x,y)); 118 } 119 120 cout<<solve(xb, yb)<<endl; 121 } 122 return 0; 123 }