刘汝佳紫书练习4-1

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;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值