123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #define X 10
- #define Y 9
- using std::cin;
- int dx[4] = {1, 0, -1, 0};
- int dy[4] = {0, 1, 0, -1};
- int hx[8] = {2, 2, 1, -1, -2, -2, 1, -1};
- int hy[8] = {1, -1, 2, 2, 1, -1, -2, -2};
- char board[X + 1][Y + 1];
- bool is_out(int x, int y) {
- return x < 1 || X < x || y < 1 || Y < y;
- }
- bool solve(int x, int y) {
- // Out of black palace
- if (x < 1 || 3 < x || y < 4 || 6 < y) return true;
- // Check cannon and chariot
- for (int i = 0; i < 4; i++) {
- int nx = x + dx[i];
- int ny = y + dy[i];
- char c = 0;
- int gap = 0;
- while (gap < 2 && !is_out(nx, ny)) {
- c = board[nx][ny];
- nx += dx[i];
- ny += dy[i];
- if (c == 0) continue;
- switch (c) {
- case 'G': case 'R':
- if (gap == 0) return true;
- break;
- case 'C':
- if (gap == 1) return true;
- break;
- }
- gap++;
- }
- }
- for (int i = 0; i < 8; i++) {
- int nx = x + hx[i];
- int ny = y + hy[i];
- if (is_out(nx, ny)) continue;
- if (board[nx][ny] == 'H') {
- nx -= hx[i] / 2; // Red to black, not black to red!
- ny -= hy[i] / 2;
- if (board[nx][ny] == 0) return true;
- }
- }
- return false;
- }
- void print_board() {
- printf(" 123456789\n");
- for (int x = 1; x <= X; x++) {
- printf("%2d", x);
- for (int y = 1; y <= Y; y++) {
- if (board[x][y] == 0) {
- printf(".");
- } else {
- printf("%c", board[x][y]);
- }
- }
- printf("\n");
- }
- }
- int main() {
- int N, gx, gy;
- for (;;) {
- cin >> N >> gx >> gy;
- if (N == 0 && gx == 0 && gy == 0) break;
- memset(board, 0, sizeof(board));
- char ch;
- int x, y;
- for (int n = 0; n < N; n++) {
- cin >> ch >> x >> y;
- board[x][y] = ch;
- }
- bool checkmate = true;
- for (int nx = gx + 1, ny = gy; !is_out(nx, ny); nx++) {
- char c = board[nx][ny]; // For "flying general"
- if (c == 0) continue;
- if (c == 'G') checkmate = false;
- break;
- }
- for (int i = 0; i < 4; i++) {
- int nx = gx + dx[i];
- int ny = gy + dy[i];
- checkmate &= solve(nx, ny);
- }
- printf(checkmate ? "YES\n" : "NO\n");
- }
- }
|