# Xiangqi UVA - 1589

13 篇文章 0 订阅
12 篇文章 0 订阅

#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<iomanip>
#define ll long long

using namespace std;

int n,x,y,a,b;
int xq[11][10];
struct qz{
char z;
int x,y;
}s[10];

bool GG(int a1, int b1) {
if(b1 == b) {
for(int i = a - 1; i > a1; i--) if(xq[i][b] != 0) return false;
return true;
}
return false;
}

bool RG(int a1, int b1,int a2, int b2){
if(a1 == a2) {
int y1 = b1,y2 = b2;
if(y1>y2) swap(y1,y2);
for(int i = y1 + 1; i < y2; i++) if(xq[a1][i] != 0) return false;
return true;
}
if(b1 == b2){
int x1 = a1,x2 = a2;
if(x1>x2) swap(x1,x2);
for(int i = x1 + 1; i < x2; i++) if(xq[i][b1] != 0) return false;
return true;
}
return false;
}

bool CG(int a1, int b1,int a2, int b2){
if(a1 == a2) {
int y1 = b1,y2 = b2;
if(y1>y2) swap(y1,y2);
for(int i = y1+1; i < y2; i++) if(xq[a1][i] != 0) return true;
return false;
}
if(b1 == b2){
int x1 = a1,x2 = a2;
if(x1>x2) swap(x1,x2);
for(int i = x1+1; i < x2; i++) if(xq[i][b1] != 0) return true;
return false;
}
return false;
}

bool HG(int a1, int b1,int a2, int b2){
if((a1 == (a2 - 2)&&b1 == (b2 - 1))||((a1 == (a2 - 2)&&b1 == (b2 + 1)))) {
if(xq[a2 - 1][b2] == 0) return true;
}
if((a1 == (a2 + 2)&&b1 == (b2 - 1))||((a1 == (a2 + 2)&&b1 == (b2 + 1)))) {
if(xq[a2 + 1][b2] == 0) return true;
}
if((a1 == (a2 - 1)&&b1 == (b2 - 2))||((a1 == (a2 + 1)&&b1 == (b2 - 2)))) {
if(xq[a2][b2 - 1] == 0) return true;
}
if((a1 == (a2 - 1)&&b1 == (b2 + 2))||((a1 == (a2 + 1)&&b1 == (b2 + 2)))) {
if(xq[a2][b2 + 1] == 0) return true;
}
return false;
}
bool G(int a1,int b1) {
if(a1<1||a1>3||b1<4||b1>6) return true;
for(int i = 0; i < n; i++){
if(s[i].x == a1&s[i].y == b1) continue;
if(s[i].z == 'G'){
if(GG(a1,b1)) return true;
} else if(s[i].z == 'R'){
if(RG(a1, b1, s[i].x, s[i].y)) return true;
} else if(s[i].z == 'H'){
if(HG(a1, b1, s[i].x, s[i].y)) return true;
} else if(s[i].z == 'C') {
if(CG(a1, b1, s[i].x, s[i].y)) return true;
}
}
return false;
}

int main(){

while(1) {
scanf("%d%d%d", &n, &x, &y);
if(n == 0) break;
memset(xq, 0, sizeof(xq));
for(int i = 0; i < n; i++) {
getchar();
scanf("%c%d%d", &s[i].z, &s[i].x, &s[i].y);
xq[(s[i].x)][(s[i].y)] = s[i].z;
if(s[i].z == 'G') { a = s[i].x; b = s[i].y; }
}
//cout << G(x,y-1)<<G(x,y+1)<<G(x-1,y)<<G(x+1,y) << endl;
if(G(x,y-1)&&G(x,y+1)&&G(x-1,y)&&G(x+1,y)) puts("YES");
else puts("NO");
}
return 0;
}


• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 打赏
• 0
评论
11-28 407
06-08 228
04-04 971
08-02 440
11-21 2066
07-15 557
01-27 260
07-18 484
02-06 938
06-11
12-21
08-02 2053
02-12
06-13

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

Whowell

¥1 ¥2 ¥4 ¥6 ¥10 ¥20

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