UVA1589(HDU4121)
来源:互联网 发布:管家婆软件有哪几种 编辑:程序博客网 时间:2024/05/21 05:41
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”.
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 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 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”.
There is a blank line between two test cases. The input ends by 0 0 0.OutputFor each test case, if the situation is checkmate, output a single word ‘YES’, otherwise output the word ‘NO’.
Sample Input
2 1 4G 10 5R 6 43 1 5H 4 5G 10 5C 7 50 0 0Sample Output
YESNOHint
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 above.
就是给出一个象棋残局,问是否绝杀,并且黑方只有一个帅(其他规则与象棋走法一致)
坑点:
1.将可以吃掉将军的棋子
2.马的蹩脚
3.炮和将中间有且只有一个棋子的时候才能吃掉将
4.车和将中间没有棋子时才能吃将
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int s1[20],s2[20],n;
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
char a[20][20];
int check(int x,int y)
{
if(x<1||x>3)
return -2;
if(y<4||y>6)
return -2;
int i,j,k,p,q,r,t;
for(i=0;i<n;i++)
{
j=s1[i];
k=s2[i];
if(x==j&&y==k)
continue;
if(a[i][0]=='R'||a[i][0]=='G')
{
if(j==x)
{
if(k<y)
{
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(p==x&&q>k&&q<y)
break;
}
if(r==n)
return 0;
}
else
if(k>y)
{
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(p==x&&q>y&&q<k)
break;
}
if(r==n)
return 0;
}
}
else
if(k==y)
{
if(j<x)
{
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(q==y&&p>j&&p<x)
break;
}
if(r==n)
return 0;
}
else
if(j>x)
{
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(q==y&&p>x&&p<j)
break;
}
if(r==n)
return 0;
}
}
}
else
if(a[i][0]=='H')
{
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(p==x&&q==y)
continue;
if(q==k&&p==j-1)
break;
}
if(r==n)
{
if(j-2==x&&k-1==y)
return 2;
if(j-2==x&&k+1==y)
return 2;
}
for(r=0;r<n;r++)
{
if(p==x&&q==y)
continue;
p=s1[r];
q=s2[r];
if(q==k&&p==j+1)
break;
}
if(r==n)
{
if(j+2==x&&k-1==y)
return 2;
if(j+2==x&&k+1==y)
return 2;
}
for(r=0;r<n;r++)
{
if(p==x&&q==y)
continue;
p=s1[r];
q=s2[r];
if(p==j&&q==k-1)
break;
}
if(r==n)
{
if(j-1==x&&k-2==y)
return 2;
if(j+1==x&&k-2==y)
return 2;
}
for(r=0;r<n;r++)
{
if(p==x&&q==y)
continue;
p=s1[r];
q=s2[r];
if(p==j&&q==k+1)
break;
}
if(r==n)
{
if(j-1==x&&k+2==y)
return 2;
if(j+1==x&&k+2==y)
return 2;
}
}
else
if(a[i][0]=='C')
{
if(j!=x&&k!=y)
continue;
if(j==x)
{
if(k<y)
{
t=0;
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(p==x&&q==y)
continue;
if(p==x&&q>k&&q<y)
t++;
}
if(t==1)
return 3;
}
else
if(k>y)
{
t=0;
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(p==x&&q==y)
continue;
if(p==x&&q>y&&q<k)
t++;
}
if(t==1)
return 3;
}
}
else
if(k==y)
{
if(j<x)
{
t=0;
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(p==x&&q==y)
continue;
if(q==y&&p>j&&p<x)
t++;
}
if(t==1)
return 3;
}
else
if(j>x)
{
t=0;
for(r=0;r<n;r++)
{
p=s1[r];
q=s2[r];
if(p==x&&q==y)
continue;
if(q==y&&p>x&&p<j)
t++;
}
if(t==1)
return 3;
}
}
}
}
return -1;
}
int main()
{
int i,j,k,x1,y1,x2,y2,t,x,y,ca=1;
while(scanf("%d%d%d",&n,&x1,&y1)!=EOF)
{
if(n==0&&x1==0&&y1==0)
break;
for(i=0;i<n;i++)
scanf("%s%d%d",a[i],&s1[i],&s2[i]);
for(i=0;i<4;i++)
{
x2=x1+dir[i][0];
y2=y1+dir[i][1];
t=check(x2,y2);
if(t==-1)
break;
}
//printf("%d:",ca++);
if(i==4)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
R 2 2
G 10 5
2 1 5
H 3 5
C 10 5
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
1
1 4
G 10 4
3 1 4
G 10 4
R 10 3
R 10 5
- UVA1589(HDU4121)
- hdu4121 Xiangqi && uva1589 Xiangqi (模拟)
- HDU4121 UVa1589 Xiangqi 解题报告
- BFS、模拟:UVa1589/POJ4001/hdu4121-Xiangqi
- UVa1589(未ac)
- uva1589
- UVa1589
- UVa1589
- UVA1589
- hdu4121/poj 4001 Xiangqi(模拟)
- 象棋模拟 HDU4121 (Java实现)
- hdu4121 xiangqi
- hdu4121 xiangqi
- hdu4121 Xiangqi
- 算法竞赛入门经典(刘汝佳)习题4-1 UVa1589
- Uva1589 - Xiangqi
- uva1589象棋
- Uva1589象棋
- Java WebSocket构建简易聊天web程序
- 作业
- Java并发编程:CountDownLatch、CyclicBarrier和Semaphore
- 确定比赛名次 (拓扑排序)
- LCA详解(洛谷模板题)
- UVA1589(HDU4121)
- 陆吾生讲座 最优化问题的数学基础
- 作业
- 顺序串各种基本运算的算法
- ssm 文件上传与下载
- mycat http://www.mycat.io/数据库分库分表中间件
- nubia z17/Z17mini/Z11 内核源码已开源
- 作业
- 2.1数据抽象引导