4746: Xiangqi

时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte

总提交: 15            测试通过:2

描述

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 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”.

输入

The input contains multiple 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.

输出

For each test case, if the situation is checkmate, output a single word ‘YES’, otherwise output the word ‘NO’.

样例输入

2 1 4
G 10 5
R 6 4

3 1 5
H 4 5
G 10 5
C 7 5

0 0 0

样例输出

YES
NO

提示

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.

题意:黑方只有一枚将棋,红方则有多枚棋子,此时黑方动,判断黑方是否已经无路可走,即被将死。

题解:模拟判断红方棋子的走向,再判断黑将4个方向移动是否能被红方的棋子所将死。

 #include "iostream"
#include "string.h"
using namespace std;
int weizhi[][];
int wxl(int a,int b)
{
int i,flag;//flag判断此位置是否有棋子和有几个棋子
// 判断马的走位
if((a-)>&&(b-)>&&weizhi[a-][b-]==&&!weizhi[a-][b-])return ;
if((a-)>&&(b+)<=&&weizhi[a-][b+]==&&!weizhi[a-][b+])return ;
if((a-)>&&(b-)>&&weizhi[a-][b-]==&&!weizhi[a-][b-])return ;
if((a+)<=&&(b-)>&&weizhi[a+][b-]==&&!weizhi[a+][b-])return ;
if((a+)<=&&(b-)>&&weizhi[a+][b-]==&&!weizhi[a+][b-])return ;
if((a+)<=&&(b+)<=&&weizhi[a+][b+]==&&!weizhi[a+][b+])return ;
if((a-)>&&(b+)<=&&weizhi[a-][b+]==&&!weizhi[a-][b+])return ;
if((a+)<=&&(b+)<=&&weizhi[a+][b+]==&&!weizhi[a+][b+])return ; // 判断炮和车和将和帅是否直接对面
flag=;
for(i=a-;i>;i--)
{
if(!flag&&weizhi[i][b]==||weizhi[i][b]==)return ;
if(weizhi[i][b]==&&flag==)return ;
if(weizhi[i][b]!=)flag++;//判断炮有几个跳跃点
}
flag=;
for(i=a+;i<=;i++)
{
if(!flag&&weizhi[i][b]==||weizhi[i][b]==)return ;
if(weizhi[i][b]==&&flag==)return ;
if(weizhi[i][b]!=)flag++;
}
flag=;
for(i=b-;i>;i--)
{
if(!flag&&weizhi[a][i]==||weizhi[a][i]==)return ;
if(weizhi[a][i]==&&flag==)return ;
if(weizhi[a][i]!=)flag++;
}
flag=;
for(i=b+;i<;i++)
{
if(!flag&&weizhi[a][i]==||weizhi[a][i]==)return ;
if(weizhi[a][i]==&&flag==)return ;
if(weizhi[a][i]!=)flag++;
}
return ;//黑将不会被将军
} int main()
{
int i,k,n,m,b,c,flag;
char a;
while(cin>>n>>m>>k)
{
if(n==&&m==&&k==)break;
memset(weizhi,,sizeof weizhi);//给位置初始化为0
for(i=;i<n;i++)
{
cin>>a>>b>>c;
if(a=='G')weizhi[b][c]=;//4表示这个点的棋子是帅
if(a=='H')weizhi[b][c]=;//5表示这个点的棋子是马
if(a=='C')weizhi[b][c]=;//2表示这个点的棋子是炮
if(a=='R')weizhi[b][c]=;//3表示这个点的棋子是车
}
//判断将的4个移动方向是否还会被将军
if(m+<=&&m+>&&k>=&&k<=)//因为黑将的移动是有范围的,所以不能越界
{
flag=wxl(m+,k);
if(flag)
{
cout<<"NO"<<'\n';continue;
}
}
if(m-<=&&m->&&k>=&&k<=)
{
flag=wxl(m-,k);
if(flag)
{
cout<<"NO"<<'\n';continue;
}
}
if(m<=&&m>&&k+>=&&k+<=)
{
flag=wxl(m,k+);
if(flag)
{
cout<<"NO"<<'\n';continue;
}
}
if(m<=&&m>&&k->=&&k-<=)
{
flag=wxl(m,k-);
if(flag)
{
cout<<"NO"<<'\n';continue;
}
}
cout<<"YES"<<'\n';
}
}
//但是TOJ有一点不用考虑,我也没考虑,其他oj则需要考虑,就是红方是用帅来将军的,这是轮到黑方
//移子,那么应该是黑方胜,而TOJ则还是红方胜

Xiangqi(简单模拟)的更多相关文章

  1. java web学习总结(二十二) -------------------简单模拟SpringMVC

    在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...

  2. WPF简单模拟QQ登录背景动画

    介绍 之所以说是简单模拟,是因为我不知道QQ登录背景动画是怎么实现的.这里是通过一些办法把它简化了,做成了类似的效果 效果图 大体思路 首先把背景看成是一个4行8列的点的阵距,X轴Y轴都是距离70.把 ...

  3. Linux 内核 链表 的简单模拟(2)

    接上一篇Linux 内核 链表 的简单模拟(1) 第五章:Linux内核链表的遍历 /** * list_for_each - iterate over a list * @pos: the & ...

  4. Linux 内核 链表 的简单模拟(1)

    第零章:扯扯淡 出一个有意思的题目:用一个宏定义FIND求一个结构体struct里某个变量相对struc的编移量,如 struct student { int a; //FIND(struct stu ...

  5. JavaWeb学习总结(四十九)——简单模拟Sping MVC

    在Spring MVC中,将一个普通的java类标注上Controller注解之后,再将类中的方法使用RequestMapping注解标注,那么这个普通的java类就够处理Web请求,示例代码如下: ...

  6. 简单模拟Hibernate的主要功能实现

    在学习期间接触到Hibernate框架,这是一款非常优秀的O/R映射框架,大大简化了在开发web项目过程中对数据库的操作.这里就简单模拟其底层的实现. /*******代码部分,及其主要注解***** ...

  7. 【HDU 4452 Running Rabbits】简单模拟

    两只兔子Tom和Jerry在一个n*n的格子区域跑,分别起始于(1,1)和(n,n),有各自的速度speed(格/小时).初始方向dir(E.N.W.S)和左转周期turn(小时/次). 各自每小时往 ...

  8. Jquery源码分析与简单模拟实现

    前言 最近学习了一下jQuery源码,顺便总结一下,版本:v2.0.3 主要是通过简单模拟实现jQuery的封装/调用.选择器.类级别扩展等.加深对js/Jquery的理解. 正文 先来说问题: 1. ...

  9. (hdu step 8.1.6)士兵队列训练问题(数据结构,简单模拟——第一次每2个去掉1个,第二次每3个去掉1个.知道队伍中的人数&lt;=3,输出剩下的人 )

    题目: 士兵队列训练问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  10. NYOJ 题目77 开灯问题(简单模拟)

    开灯问题 时间限制:3000 ms  |            内存限制:65535 KB 难度:1           描述 有n盏灯,编号为1~n,第1个人把所有灯打开,第2个人按下所有编号为2 ...

随机推荐

  1. Git常用功能记录

    1. git查看某个文件的修改历史 git log --pretty 然后使用下面的命令可列出文件的所有改动历史,注意,这里着眼于具体的一个文件,而不是git库,如果是库,那改动可多了去了- git ...

  2. python多进程multiprocessing模块中Queue的妙用

    最近的部门RPA项目中,小爬为了提升爬虫性能,使用了Python中的多进程(multiprocessing)技术,里面需要用到进程锁Lock,用到进程池Pool,同时利用map方法一次构造多个proc ...

  3. Windows SFTP 的安装

    用于Windows系统的免费SFTP服务器-Free SFTP Servers 前不久,有人问我:“怎么从 Linux 系统传文件到 Windows 服务器,不能用 FTP 协议.” 文件数量不大.用 ...

  4. 【速读】——Shangxuan Tian——【ICCV2017】WeText_Scene Text Detection under Weak Supervision

    Shangxuan Tian——[ICCV2017]WeText_Scene Text Detection under Weak Supervision 目录 作者和相关链接 文章亮点 方法介绍 方法 ...

  5. Caravel–一款开源OLAP+数据可视化分析前端工具,支持Druid和Kylin

    参考此文:http://lxw1234.com/archives/2016/06/681.htm

  6. (cvpr2019) The Degradation Model and Solution of DPSR

    新的退化模型: $y = (x\downarrow_{s}) \otimes k + n $ 其中$\downarrow_{s}$代表尺度因子为$s$的双三次下采样,$y$表达的是低分辨率图像(经过双 ...

  7. vue-cli —— 局部修改Element样式

    最近在做vue项目时用到了Element,发现这玩意儿用起来很舒服,很新颖,上手也很快,而且效果足够酷炫.但是后面发现一个很大的问题,那就是Element的样式有限,这极大地限制了项目的应用广度,所以 ...

  8. JS运算符、NaN

    一.关系运算符  (< <= > >= == === != !==) 判断符号左右的两个数据的大小之间的关系,运算结果是一个布尔类型的值 ==   只判断值 ===即判断值并且 ...

  9. 【Rice】Cultivar versus Variety

    From Cindy Haynes, Department of Horticulture   As a horticulturist, it is important that I use the ...

  10. 关于LinQ中“from"前置的原因

    原文地址:http://blog.csdn.net/yuzifen/article/details/6754003 概括来说是:为了IDE的智能感知(Intelisence)功能,(或说为了进行类型推 ...