http://acm.hdu.edu.cn/showproblem.php?pid=4121
模拟
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <climits>
using namespace std;
const int dx[5]={0,0,0,1,-1};
const int dy[5]={0,1,-1,0,0};
const int dhx[8]={1,2,2,1,-1,-2,-2,-1};
const int dhy[8]={-2,-1,1,2,2,1,-1,-2};
const int bx[8]={1,1,1,1,-1,-1,-1,-1};
const int by[8]={-1,-1,1,1,1,1,-1,-1};
int a[20][20];
int max4(int a,int b,int c,int d)
{
return max(max(a,b),max(c,d));
}
bool in(int x,int y)
{
return (x>0 && x<11 && y>0 && y<10);
}
bool in_g(int x,int y)
{
return ((y>3 && y<7 && x<4 && x>0)||(y>3 && y<7 && x<11 && x>7));
}
int main()
{
char ch;
int c,x0,y0,t1,t2,gx,gy;
//while (scanf("%d%d%d",&c,&x0,&y0)!=EOF && c && x0 && y0)
while (cin>>c>>x0>>y0 && c+x0+y0)
{
memset(a,-1,sizeof(a));
for (int i=0;i<c;i++)
{
cin>>ch>>t1>>t2;
//scanf("%s%d%d",ch,&t1,&t2);
if (ch=='G'){a[t1][t2]=0;gx=t1;gy=t2;}
else if (ch=='R') a[t1][t2]=1;
else if (ch=='H') a[t1][t2]=2;
else if (ch=='C') a[t1][t2]=3;
}
bool flag=true;
for (int i=1;i<5;i++)
{
bool ju=false;
int tx=x0+dx[i];
int ty=y0+dy[i];
if (!in_g(tx,ty)) continue;
for (int j=0;j<8;j++)
{
int hx=tx+dhx[j];
int hy=ty+dhy[j];
if (!in(hx,hy)) continue;
if (a[tx+bx[j]][ty+by[j]]==-1 && a[hx][hy]==2)
{
ju=true;
break;
}
}
if (ju) continue;
bool j1=false;
for (int j=1;j<=10-tx;j++)
{
if (a[tx+j][ty]!=-1)
{
if (!j1 && a[tx+j][ty]==1) {ju=true;break;}
else if (!j1 && a[tx+j][ty]!=-1) {j1=true;continue;}
if (j1 && a[tx+j][ty]==3) {ju=true;break;}
else if (j1 && a[tx+j][ty]!=-1) break;
}
}
if (ju) continue;
j1=false;
for (int j=1;j<=tx-1;j++)
{
if (a[tx-j][ty]!=-1)
{
if (!j1 && a[tx-j][ty]==1) {ju=true;break;}
else if (!j1 && a[tx-j][ty]!=-1){j1=true;continue;}
if (j1 && a[tx-j][ty]==3) {ju=true;break;}
else if (j1 && a[tx-j][ty]!=-1) break;
}
}
if (ju) continue;
j1=false;
for (int j=1;j<=9-ty;j++)
{
if (a[tx][ty+j]!=-1)
{
if (!j1 && a[tx][ty+j]==1) {ju=true;break;}
else if (!j1 && a[tx][ty+j]!=-1) {j1=true;continue;}
if (j1 && a[tx][ty+j]==3) {ju=true;break;}
else if (j1 && a[tx][ty+j]!=-1) break;
}
}
if (ju) continue;
j1=false;
for (int j=1;j<=ty-1;j++)
{
if (a[tx][ty-j]!=-1)
{
if (!j1 && a[tx][ty-j]==1) {ju=true;break;}
else if (!j1 && a[tx][ty-j]!=-1) {j1=true;continue;}
if (j1 && a[tx][ty-j]==3) {ju=true;break;}
else if (j1 && a[tx][ty-j]!=-1)break;
}
}
if (ju) continue;
bool j2;//false no zi
if (ty==gy)
{
j2=false;
for (int k=tx+1;k<gx;k++)
if (a[k][gy]!=-1) {j2=true;break;}
}
else j2=true;
if (!j2) ju=true;//can checkmate
if (ju==false) {flag=false;break;}
}
if (flag) cout<<"YES"<<endl;//printf("YES\n");
else cout<<"NO"<<endl;//printf("NO\n");
}
return 0;
}