总体思路: 将不能走的打标记。
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;
struct node{
int i,j;
char type;
}queue[10];
char xiangqi[12][11];
int beat[11][10],X,Y;
void setwall();
void mark(char , int , int);
bool pd_h(int , int);
int main()
{
int N,rear=0,front=0;
while(cin >> N && N!=0) {
memset(xiangqi,0,sizeof(xiangqi));
setwall();
memset(beat,0,sizeof(beat));
memset(queue,0,sizeof(queue));
front=0;rear=0;
cin>> X >> Y;
xiangqi[X][Y] = 'B';
while(N--) {
cin >> queue[rear].type >> queue[rear].i >>queue[rear].j;
xiangqi[queue[rear].i][queue[rear].j] = queue[rear].type;
rear++;
}
while(front<rear) {
mark(queue[front].type,queue[front].i,queue[front].j);
front++;
}
int ok=0;
if( X<=2 && !beat[X+1][Y] ) ok=1;
if( X>=2 && !beat[X-1][Y] ) ok=1;
if( Y<=5 && !beat[X][Y+1] ) ok=1;
if( Y>=5 && !beat[X][Y-1] ) ok=1;
if(ok) cout << "NO" <<endl;
else cout << "YES" <<endl;
}
}
void setwall() {
int i;
for(i = 1; i <= 10; i++) {
for(int j = 1; j <= 9; j++) xiangqi[i][j] = '*';
}
}
bool pd_h(int x, int y) {
if(x<=10 && x>=1 && y<=9 && y>=1) return 1;
}
void mark(char type, int i, int j) {
switch (type)
{
case 'G':{//帅的标记
int k=1;
i--;
while(k)
{
beat[i][j]=1;
if(xiangqi[i][j] != '*' || i<=1) k--;
i--;
}
break;
}
case 'R':{//车的标记跳过接下来
int f=i,g=j;
do {
i++;
beat[i][j] = 1;
} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && i < 10);
i = f;
do {
i--;
beat[i][j] = 1;
} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && i > 1);
i = f;
do {
j++;
beat[i][j] = 1;
} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && j < 9);
j = g;
do {
j--;
beat[i][j] = 1;
} while( (xiangqi[i][j]=='B' || xiangqi[i][j] == '*') && j > 1);
break;
}
case 'C':{//炮 最难的啊啊啊
if(j<4 && i>3) break;
else if(j>6 && i>3) break;
else if(i>3) {
int f = i;
do i--;
while( xiangqi[i][j]=='*' && i>1);
if(xiangqi[i][j]=='B' || i==1) break;
else {
do {
beat[--i][j]=1;
}while(i>1 && (xiangqi[i][j] == '*' || xiangqi[i][j]=='B'));
}
}
else {
int k = 2, g = j;
while (k && j<9) {
j++;
if(k==1) beat[i][j]=1;
if(xiangqi[i][j]!='*' && xiangqi[i][j]!='B');
k--;
}
j=g;k=2;
while (k && j>1)
{
j--;
if(k==1) beat[i][j]=1;
if(xiangqi[i][j]!='*' && xiangqi[i][j]!='B');
k--;
}
}
break;
}
case 'H':{// 从周围八个点入手;
int f = i, g = j;
f+=2;
if(xiangqi[i+1][j]=='*') {
if(pd_h(i+2,j-1)) beat[i+2][j-1]=1;
if(pd_h(i+2,j+1)) beat[i+2][j+1]=1;
}
if(xiangqi[i-1][j]=='*') {
if(pd_h(i-2,j-1)) beat[i-2][j-1]=1;
if(pd_h(i-2,j+1)) beat[i-2][j+1]=1;
}
if(xiangqi[i][j+1]=='*') {
if(pd_h(i-1,j+2)) beat[i-1][j+2]=1;
if(pd_h(i+1,j+2)) beat[i+1][j+2]=1;
}
if(xiangqi[i][j-1]=='*') {
if(pd_h(i-1,j-2)) beat[i-1][j-2]=1;
if(pd_h(i+1,j-2)) beat[i+1][j-2]=1;
}
break;
}
}
return ;
}