Xiangqi is one of the most popular two-player board games in China.
The game represents a battle between two armies with the goal of
capturing the enemy’s “general” piece. In this problem, you are given
a situation of later stage in the game. Besides, the red side has
already “delivered a check”. Your work is to check whether the
situation is “checkmate”.
![]()
Now we introduce some basic rules of
Xiangqi. Xiangqi is played on a 10 × 9 board and the pieces are placed
on the intersections (points). The top left point is (1,1) and the
bottom right point is (10,9). There are two groups of pieces marked by
black or red Chinese characters, belonging to the two players
separately. During the game, each player in turn moves one piece from
the point it occupies to another point. No two pieces can occupy the
same point at the same time. A piece can be moved onto a point
occupied by an enemy piece, in which case the enemy piece is“captured”
and removed from the board. When the general is in danger of being
captured by the enemy player on the enemy player’s next move, the
enemy player is said to have “delivered a check”. If the general’s
player can make no move to prevent the general’s capture by next enemy
move, the situation is called “checkmate”. We only use 4 kinds of
pieces introducing as follows:
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
figure above). “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
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 figure below), which is called “hobbling the
horse’s leg”. Now you are given a situation only containing a black
general, a red general and several red chariots, cannons and horses,
and the red side has delivered a check. Now it turns to black side’s
move. Your job is to determine that whether this situation is
“checkmate”.
![]()
Input
The input contains no more than 40 test cases. For
each test case, the first line contains three integers representing
the number of red pieces N (2 ≤ N ≤ 7) and the position of the black
general. The following N lines contain details of N red pieces. For
each line, there are a char and two integers representing the type and
position of the piece (type char ‘G’ for general, ‘R’ for chariot, ‘H’ for horse and ‘C’ for cannon). We guarantee that the situation is legal and the red side has delivered the check. There is a blank line between two test cases. The input ends by ‘0 0 0’.
Output
For each test case, if the situation is checkmate, output a single word ‘YES’,otherwise output the word ‘NO’. Hint: In the first situation, the black general is checked by chariot and “flying general”. In the second situation, the black general can move to (1, 4) or (1, 6) to stop check. See the figure on the right.
Sample Input
2 1 4
G 10 5
R 6 43 1 5
H 4 5
G 10 5
C 7 5
0 0 0
Sample Output
YES
NO
我只想说 ———— 坑太多!
真的是 无fuck说
首先,输出格式,“There is a blank line between two test cases.”完全没用 ,不用考虑多输出空行;
其次,当将和帅照面的时候,这时黑方先走,黑将可以直接把红帅将死,然后胜利,然而,不可以!我把这一步删除立马就过了;
还有就是,红方的棋在黑将的框框里时,黑将可以吃掉它!然后再判断会不会被其他的红棋将死;(记的判断完之后再把吃掉的棋子复原,因为还要判断其他情况)。
#include<bits/stdc++.h>
using namespace std;
int Map[11][10]={0};
struct Info{
char name[3];
int x,y;
}pi[10];
int Pao(int x,int y,int xg,int yg){
int n=0;
if(yg!=y) return 0;
if(xg>x){
int xx=xg;xg=x;x=xx;
}
for(int i=xg+1;i<x;i++){
if(Map[i][y]==1)
n++;
if(n>1) return 0;
}
if(n==1) return 1;
else return 0;
}
int Shuai(int x,int y,int xg,int yg){
//int n=0;
if(y!=yg) return 0;
if(xg>x){
int xx=xg;xg=x;x=xx;
}
for(int i=xg+1;i<x;i++){
if(Map[i][y]==1)
return 0;
}
return 1;
}
int Che(int x,int y,int xg,int yg){
if(x!=xg&&y!=yg) return 0;
if(y==yg){
if(xg>x){
int xx=xg;xg=x;x=xx;
}
for(int i=xg+1;i<x;i++){
if(Map[i][y]==1)
return 0;
}
}
else if(x==xg){
if(yg>y){
int yy=yg;yg=y;y=yy;
}
for(int i=yg+1;i<y;i++){
if(Map[x][i]==1)
return 0;
}
}
return 1;
}
int Ma(int x,int y,int xg,int yg){
if(x==xg||y==yg) return 0;
if(x+2==xg&&fabs(y-yg)==1){
if(Map[x+1][y]==0)//没有阻碍
return 1;
}
if(x-2==xg&&fabs(y-yg)==1){
if(Map[x-1][y]==0)
return 1;
}
if(y+2==yg&&fabs(x-xg)==1){
if(Map[x][y+1]==0)
return 1;
}
if(y-2==yg&&fabs(x-xg)==1){
if(Map[x][y-1]==0)
return 1;
}
return 0;
}
int main()
{
int N,xg,yg;int first=0;
while(scanf("%d%d%d",&N,&xg,&yg)!=EOF){
int s;
memset(Map,0,sizeof(Map));
if(!N&&!xg&&!yg) return 0;
//if(first++) cout<<endl;
for(int i=1;i<=N;i++){
getchar();
cin>>pi[i].name;
if(pi[i].name[0]=='G')
{
s=i;
}
cin>>pi[i].x>>pi[i].y;
Map[pi[i].x][pi[i].y]=1;
}
//if(Shuai(xg,yg,pi[s].x,pi[s].y)){
// cout<<"NO\n";continue;
//}
int flag=1;//int xu=0,xd=0,yl=0,yr=0;
int g[5]={0};
if(xg>1) g[0]=1;//往shang走
if(yg>4) g[2]=1;//zuo
if(xg<3) g[1]=1;//xia
if(yg<6) g[3]=1;//you
//g[4]=1;
//if(Shuai())
int fl=0;
for(int j=0;j<4;j++){
if(g[j]==0) continue;
int xj,yj;
if(j==0) {
xj=xg-1;yj=yg;
if(Map[xj][yj]){//上边有棋子就把它吃了
Map[xj][yj]=0;fl=1;
}
}
else if(j==1){
xj=xg+1;yj=yg;
if(Map[xj][yj]){
Map[xj][yj]=0;fl=1;
}
}
else if(j==2){
xj=xg;yj=yg-1;
if(Map[xj][yj]){
Map[xj][yj]=0;fl=1;
}
}
else if(j==3){
xj=xg;yj=yg+1;
if(Map[xj][yj]){
Map[xj][yj]=0;fl=1;
}
}
flag=1;
for(int i=1;i<=N;i++){
if(Map[pi[i].x][pi[i].y]==0) continue;
if(pi[i].name[0]=='G'){
if(Shuai(pi[i].x,pi[i].y,xj,yj)==1){
flag=0;break;
}
}
else if(pi[i].name[0]=='R'){
if(Che(pi[i].x,pi[i].y,xj,yj)==1){
flag=0;break;
}
}
else if(pi[i].name[0]=='H'){
if(Ma(pi[i].x,pi[i].y,xj,yj)==1){
flag=0;break;
}
}
else if(pi[i].name[0]=='C'){
if(Pao(pi[i].x,pi[i].y,xj,yj)==1){
flag=0;break;
}
}
}
if(flag){
break;
}
if(fl) {
Map[xj][yj]=1;fl=0;
}
// cout<<j<<"---"<<xj<<"---"<<yj<<"----"<<flag<<endl;
}
if(flag) cout<<"NO\n";
else cout<<"YES\n";
}
return 0;
}