在temp数组中把红方所有棋子能到达的位置标‘1’,最后在黑将能走的地方判断一下有没有没被标‘1’的 没有则被将死。
#include <iostream>
#include <cstdio>
using namespace std;
char board[10][9]={},temp[10][9]={};
int G_G(int i,int j)
{
for(int i=7;i<10;i++)
{
for(int j=3;j<6;j++)
if(board[i][j]=='G')
{
for(int n=i-1;n>=0;n--)
{
if(board[n][j]=='0'||board[n][j]=='1')
temp[n][j]='1';
else
{
temp[n][j]='1';
return 0;
}
}
}
}
}
void R(int i,int j)
{
for(int m=i-1;m>=0;m--)
if((board[m][j]=='0'||board[m][j]=='1')&&board[m][j]!='G')
temp[m][j]='1';
else
{
temp[m][j]='1';
break;
}
for(int m=i+1;m<10;m++)
if((board[m][j]=='0'||board[m][j]=='1')&&board[m][j]!='G')
temp[m][j]='1';
else
{
temp[m][j]='1';
break;
}
for(int n=j-1;n>=0;n--)
if((board[i][n]=='0'||board[i][n]=='1')&&board[i][n]!='G')
temp[i][n]='1';
else
{
temp[i][n]='1';
break;
}
for(int n=j+1;n<9;n++)
if((board[i][n]=='0'||board[i][n]=='1')&&board[i][n]!='G')
temp[i][n]='1';
else
{
temp[i][n]='1';
break;
}
}
void H(int i,int j)
{
if(board[i-1][j]=='0'||board[i-1][j]=='1')
{
temp[i-2][j-1]='1';temp[i-2][j+1]='1';
}
if(board[i+1][j]=='0'||board[i+1][j]=='1')
{
temp[i+2][j-1]='1';temp[i+2][j+1]='1';
}
if(board[i][j-1]=='0'||board[i][j-1]=='1')
{
temp[i-1][j-2]='1';temp[i+1][j-2]='1';
}
if(board[i][j+1]=='0'||board[i][j+1]=='1')
{
temp[i-1][j+2]='1';temp[i+1][j+2]='1';
}
}
void C(int i,int j)
{
int flag=0;
for(int m=i-1;m>=0;m--)
{
if(board[m][j]!='0')
{
flag=1;
for(int p=m-1;p>=0;p--)
{
if((board[p][j]=='0'||board[p][j]=='1')&&board[p][j]!='G')
{
temp[p][j]='1';
}
else
{
temp[p][j]='1';
flag=1;
break;
}
}
}
if(flag==1)
{
flag=0;
break;
}
}
for(int m=i+1;m<10;m++)
{
if(board[m][j]!='0')
{
flag=1;
for(int p=m+1;p<10;p++)
{
if((board[p][j]=='0'||board[p][j]=='1')&&board[p][j]!='G')
{
temp[p][j]='1';
}
else
{
temp[p][j]='1';
flag=1;
break;
}
}
}
if(flag==1)
{
flag=0;
break;
}
}
for(int n=j-1;n>=0;n--)
{
if(board[i][n]!='0')
{
flag=1;
for(int q=n-1;q>=0;q--)
{
if((board[i][q]=='0'||board[i][q]=='1')&&board[i][q]!='G')
{
temp[i][q]='1';
}
else
{
temp[i][q]='1';
flag=1;
break;
}
}
}
if(flag==1)
{
flag=0;
break;
}
}
for(int n=j+1;n<9;n++)
{
if(board[i][n]!='0')
{
flag=1;
for(int q=n+1;q<9;q++)
{
if((board[i][q]=='0'||board[i][q]=='1')&&board[i][q]!='G')
{
temp[i][q]='1';
}
else
{
temp[i][q]='1';
flag=1;
break;
}
}
}
if(flag==1)
{
flag=0;
break;
}
}
}
void start()
{
for(int i=0;i<10;i++)
for(int j=0;j<9;j++)
{
board[i][j]='0';
temp[i][j]='0';
}
}
int main()
{
//freopen("c:\\test.txt","r",stdin);
//freopen("c:\\hu.txt","w",stdout);
int T,x,y,m,n,flag=0,flag2=0;
char t;
while(cin>>T>>x>>y&&T&&x&&y)
{
start();
x--;y--;
while(T--)
{
cin>>t>>m>>n;
board[m-1][n-1]=t;
}
for(int i=0;i<10;i++)
{
for(int j=0;j<9;j++)
{
if(board[i][j]!='1'&&board[i][j]!='0')
{
if(board[i][j]=='R')
R(i,j);
else if(board[i][j]=='H')
H(i,j);
else if(board[i][j]=='C')
C(i,j);
else if(board[i][j]='G')
G_G(i,j);
}
}
}
if(x-1>=0)
if(temp[x-1][y]!='1')
flag=1;
if(x+1<=2)
if(temp[x+1][y]!='1')
flag=1;
if(y-1>=3)
if(temp[x][y-1]!='1')
flag=1;
if(y+1<=5)
if(temp[x][y+1]!='1')
flag=1;
if(flag==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
flag=0;
}
}
/*
2 1 4
G 10 5
R 6 4
3 1 5
H 4 5
G 10 5
C 7 5
2 1 5
R 4 4
G 10 5
3 1 5
G 10 4
R 5 5
H 3 7
4 1 5
G 10 4
C 6 5
H 5 5
R 1 1
5 1 5
G 10 4
C 6 5
H 5 5
H 4 5
R 1 1
3 1 5
G 10 4
C 2 7
H 3 7
3 1 5
G 10 4
R 5 5
R 1 6
4 1 5
G 10 4
R 5 5
R 1 6
H 3 7
0 0 0
*/