2016.10.14晚上写的,代码写出带wa了无数次,这种细节模拟题没啥好说的就是要细心
#include#include#include#includeusing namespace std;const int maxn = 10;char board[15][15];struct Piece{char id;int x,y;}red_pie[maxn];int n;bool checkmate(Piece t, int x, int y){if(t.x == x && t.y == y) return 0;switch(t.id){case 'G':{if(y != t.y) return 0;for(int i = x + 1; i < t.x; i++){//cout << i << endl;if(board[i][y]) return 0;}return 1;break;}case 'R':{if(y == t.y){if(x > t.x) swap(x, t.x);for(int i = x + 1; i < t.x; i++){if(board[i][y]) return 0;}return 1;}if(x == t.x){if(y > t.y) swap(y, t.y);for(int i = y + 1; i < t.y; i++){if(board[x][i]) return 0;}return 1;}return 0;break;}case 'H':{if(x == t.x + 2 && (y == t.y + 1 || y == t.y - 1) && !board[t.x + 1][t.y])return 1;if(x == t.x - 2 && (y == t.y + 1 || y == t.y - 1) && !board[t.x - 1][t.y])return 1;if(y == t.y + 2 && (x == t.x + 1 || x == t.x - 1) && !board[t.x][t.y + 1])return 1;if(y == t.y - 2 && (x == t.x + 1 || x == t.x - 1) && !board[t.x][t.y - 1])return 1;return 0;break; }case 'C':{if(y == t.y){int num = 0;if(x > t.x) swap(x, t.x);for(int i = x + 1; i < t.x; i++){if(board[i][y]) num++;}return num == 1;}if(x == t.x){int num = 0;if(y > t.y) swap(y, t.y);for(int i = y + 1; i < t.y; i++){if(board[x][i]) num++;}return num == 1;}return 0;break;}}}bool text(int x, int y){/* for(int i = 0; i < n; i++){if(red_pie[i].id == 'G' && checkmate(red_pie[i], x, y)) return 0;}*/int text = 0;if(x > 1){for(int i = 0; i < n; i++){if(checkmate(red_pie[i], x - 1, y)){// cout << "x - 1" << endl;// cout << red_pie[i].id << endl;text = 1;}}if(text == 0) return 0;else text = 0;}if(x < 3){for(int i = 0; i < n; i++){if(checkmate(red_pie[i], x + 1, y)){// cout << "x + 1" << endl;// cout << red_pie[i].id << endl;text = 1;}}if(text == 0) return 0;else text = 0;}if(y > 4){for(int i = 0; i < n; i++){if(checkmate(red_pie[i], x, y - 1)){// cout << "y - 1" << endl;// cout << red_pie[i].id << endl;text = 1;}}if(text == 0) return 0;else text = 0;}if(y < 6){for(int i = 0; i < n; i++){if(checkmate(red_pie[i], x, y + 1)){// cout << "y + 1" << endl;// cout << red_pie[i].id << endl;text = 1;}}if(text == 0) return 0;else text = 0;}return 1;}void add_pie(Piece t){board[t.x][t.y] = t.id;}int main(){//freopen("input.txt", "r", stdin);int gx, gy;while(scanf("%d%d%d", &n, &gx, &gy) == 3){memset(red_pie, 0, sizeof(red_pie));memset(board, 0, sizeof(board));//cout << n << " " << gx << " " << gy << endl;if(n == 0 && gx == 0 && gy == 0) break;for(int i = 0; i < n; i++){cin >> red_pie[i].id >> red_pie[i].x >> red_pie[i].y;//scanf("%c%d%d", &red_pie[i].id, &red_pie[i].x, &red_pie[i].y);//printf("%c %d %d\n", red_pie[i].id, red_pie[i].x, red_pie[i].y);add_pie(red_pie[i]);}if(text(gx, gy)) printf("YES\n");else printf("NO\n");}return 0;}