Test instructions give you a black to be the general's chess pieces to determine whether the red side has put the black side will die
The simulation questions attention to detail on the line, see if Black will not go in four directions
#include <cstdio> #include <cstring>using namespace std;const int N = 12;char Brd[n][n];int dx[] = {-1, 1, 0, 0} , dy[] = {0, 0,-1, 1};int hx[] = {-2,-1,-2,-1, 1, 2, 1, 2}; General Ma int hy[] = {-1,-2, 1, 2,-2,-1, 2, 1};int tx[] = {-1,-1,-1,-1, 1, 1, 1, 1}; Horse crappy int ty[] = {-1,-1, 1, 1,-1,-1, 1, 1};int cr[2], cc[2]; Record cannon coordinates int check (int r, int c) {int I, j, K, TR, TC, CNT; if (R < 1 | | r > 3 | | c < 4 | | C > 6) return 1; for (j = c-1; j > 0;--j)/Line by vehicle {if (Brd[r][j]) if (brd[r][j] = = ' R ') return 1; else break; } for (j = c + 1; J <= 9; ++j) {if (Brd[r][j]) if (brd[r][j] = = ' R ') return 1; else break; } for (i = r-1; i > 0; i)//column is car {if (Brd[i][c]) if (brd[i][c] = = ' R ') return 1; else break; } for (i = r + 1; i <=; ++i)//column is car or {if (Brd[i][c]) if (brd[i][c] = = ' R ' | | brd[i][c] = = ' G ' ) return 1; else break; } for (int k = 0; k < 2; ++k)//Cannon General {if (cr[k] = = r)//line with cannon {for (j = c-1, cnt = 0 ; J > Cc[k]; --J) if (brd[r][j]) ++cnt; if (cnt = = 1) return 1; for (j = c + 1, cnt = 0; J < cc[k]; ++j) if (brd[r][j]) ++cnt; if (cnt = = 1) return 1; if (cc[k] = = c)//column has cannon {for (i = r-1, cnt = 0; i > cr[k]; i) if (brd[i][c]) ++cnt; if (cnt = = 1) return 1; for (i = r + 1, cnt = 0; i < cr[k]; ++i) if (brd[i][c]) ++cnt; if (cnt = = 1) return 1; }} for (int k = 0; k < 8; ++k)//by General Ma {tr = r + hx[k], TC = c + hy[k]; if (Tr < 1 | | tr > TEN | | tc < 1 | | TC > 9) Continue; if (BRD[TR][TC] = = ' H ' && (!brd[r + tx[k]][c + ty[k])) return 1; } return 0;} int main () {char s[5]; int N, R, c, X, y; while (scanf ("%d%d%d", &n, &r, &c), n | | | r | | c) { memset (BRD, 0, sizeof (BRD)); Cr[0] = cc[0] = cr[1] = cc[1] = 0; while (n--) {scanf ("%s%d%d", S, &x, &y); if (s[0] = = ' C ') {if (cr[0]) cr[1] = x, cc[1] = y; else cr[0] = x, cc[0] = y; } Brd[x][y] = s[0]; } int cnt = 0; for (int i = 0; i < 4; ++i) cnt + = Check (r + dx[i], C + dy[i]); if (CNT < 4) puts ("NO"); Else puts ("YES"); } return 0;}
Xiangqi
problem DescriptionXiangqi is one of the most popular Two-player board games in China. The game represents a battle between the armies with the goal of capturing the enemy's "general" piece. In this problem, you is given a situation of later stage in the game. Besides, the red side has already "delivered a check".
Your work was to check whether the situation is "checkmate".
Now we introduce some basic rules of Xiangqi. Xiangqi is played on a 10x9 board and the pieces be placed on the intersections (points). The top left point is (bottom) and the "Right" is (10,9). There is groups of pieces marked by black or red Chinese characters, belonging to the players separately. During the game, each player in turn moves one piece from the point it occupies to another point. No. Pieces can occupy the same point at the same time. A piece can moved onto a point occupied by an enemy piece, in which case the enemy piece is ' captured ' and removed from The board. When the danger of being captured by the enemy player on the enemy player's next move, the enemy player is s Aid to has
"delivered a check". If The general's player can make no move to prevent the "s capture by next enemy move, the situation is called
"Checkmate".
We only use 4 kinds of pieces introducing as follows:
General:the generals can move and capture
one pointEither vertically or horizontally and cannot leave the "
Palace"Unless the situation called"
Flying General"(see the figure above)." Flying General "means so one general can" fly "across the board to capture the enemy general if they stand on the same L ine without intervening pieces.
Chariot:the chariots can move and capture vertically and horizontally by any distance Pieces
Cannon:the cannons move like the chariots, horizontally and vertically, but capture by jumping
exactly one piece(whether it is friendly or enemy) over-to-its target.
Horse:the Horses has 8 kinds of jumps to move and capture shown in the left figure. However, if there is any pieces lying on a point away from the horse horizontally or vertically it cannot move or capture In this direction (see the figure below), which is called "
hobbling the horse ' s leg”.
Now is given a situation only containing a black general, a red general and several red chariots, cannons and horses, And the red side has delivered a check. Now it turns to black side ' s move. Your job is to determine that whether this situation is "checkmate".
InputThe input contains no more than-test cases. For each test case, the first line contains three integers representing the number of red pieces N (2<=n<=7) and the Position of the black general. The following n lines contain details of n red pieces. For each line, there is a char and integers representing the type and position of the piece (type char ' G ' for genera L, ' R ' for Chariot, ' H ' for Horse and ' C ' for cannon. We guarantee the situation is legal and the red side have delivered the check.
There is a blank line between the test cases. The input ends by 0 0 0.
OutputFor each test case, if the situation is checkmate, and output a single word ' YES ', otherwise output the word ' NO '.
Sample Input
2 1 4G 5R 6 1 5H 4 5G 5C 7 50 0 0
Sample Output
YESNO
UVa 1589Xiangqi (Analog HDU4121)