标签:
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 1357 | Accepted: 347 |
Description

General: the generals can move and capture one point either vertically or horizontally and cannot leave the “palace” unless the situation called “flying general” (see the right figure). “Flying general”
means that one general can “fly” across the board to capture the enemy general if they stand on the same line without intervening pieces.
Chariot: the chariots can move and capture vertically and horizontally by any distance, but may not jump over intervening pieces
Cannon: the cannons move like the chariots, horizontally and vertically, but capture by jumping exactly one piece (whether it is friendly or enemy) over to its target.
Horse: the horses have 8 kinds of jumps to move and capture shown in the left figure. However, if there is any pieces lying on a point away from the horse horizontally or vertically it cannot move or capture
in that direction (see the left figure), which is called “hobbling the horse’s leg”.
Input
Output
Sample Input
2 1 4 G 10 5 R 6 4 3 1 5 H 4 5 G 10 5 C 7 5 0 0 0
Sample Output
YES NO
Hint


Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int vis[15][15];
bool search(int a,int b)
{
int i,j,t;
///这是判断马的- -
if(a-2>0&&b-1>0&&vis[a-2][b-1]==5&&!vis[a-1][b-1]) return 0;
if(b-2>0&&a-1>0&&vis[a-1][b-2]==5&&!vis[a-1][b-1]) return 0;
if(a-2>0&&b+1<=9&&vis[a-2][b+1]==5&&!vis[a-1][b+1]) return 0;
if(b+2<=9&&a-1>0&&vis[a-1][b+2]==5&&!vis[a-1][b+1]) return 0;
if(a+2<=10&&b+1<=9&&vis[a+2][b+1]==5&&!vis[a+1][b+1]) return 0;
if(b-2>0&&a+1<=10&&vis[a+1][b-2]==5&&!vis[a+1][b-1]) return 0;
if(a+2<=10&&b-1>0&&vis[a+2][b-1]==5&&!vis[a+1][b-1]) return 0;
if(b+2<=9&&a+1<=10&&vis[a+1][b+2]==5&&!vis[a+1][b+1]) return 0;
///然后是炮和车,t记录有几个隔子
t=0;
for(i=a-1; i>=1; i--)
{
if(!t&&(vis[i][b]==3||vis[i][b]==2)) return 0;///车
if(vis[i][b]==4&&t==1)return 0;///炮
if(vis[i][b]!=0) t++;
}
t=0;
for(i=a+1; i<=10; i++)
{
if(!t&&(vis[i][b]==3||vis[i][b]==2)) return 0;
if(vis[i][b]==4&&t==1)return 0;
if(vis[i][b]!=0) t++;
}
t=0;
for(i=b-1; i>=1; i--)
{
if(!t&&(vis[a][i]==3||vis[a][i]==2)) return 0;
if(vis[a][i]==4&&t==1)return 0;
if(vis[a][i]!=0) t++;
}
t=0;
for(i=b+1; i<=9; i++)
{
if(!t&&(vis[a][i]==3||vis[a][i]==2)) return 0;
if(vis[a][i]==4&&t==1)return 0;
if(vis[a][i]!=0) t++;
}
return 1;
}
int main()
{
int n,xx,yy,i,j,aa,bb,x,y;
char c;
while(~scanf("%d%d%d",&n,&xx,&yy))
{
aa=0,bb=0;
if(n==0&&xx==0&&yy==0)
break;
memset(vis,0,sizeof(vis));
for(i=1; i<=n; i++)
{
// getchar();
// scanf("%c %d %d",&c,&x,&y);
cin>>c>>x>>y;///scanf输入会出错
if(c=='G')
{
vis[x][y]=2;
aa=x,bb=y;
}
else if(c=='R')
vis[x][y]=3;
else if(c=='C')
vis[x][y]=4;
else if(c=='H')
vis[x][y]=5;
}
int k;
if(xx+1<=3&&xx+1>=1)///将不能出界
{
k=search(xx+1,yy);
if(k)
{
printf("NO\n");
continue;
}
}
if(xx-1>=1&&xx-1<=3)
{
k=search(xx-1,yy);
if(k)
{
printf("NO\n");
continue;
}
}
if(yy+1<=6&&yy+1>=4)
{
k=search(xx,yy+1);
if(k)
{
printf("NO\n");
continue;
}
}
if(yy-1>=4&&yy-1<=6)
{
k=search(xx,yy-1);
if(k)
{
printf("NO\n");
continue;
}
}
printf("YES\n");
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/d_x_d/article/details/51469825