描述

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.

题意

黑方只右1个将,红方有车马炮帅,当前黑方走,判断红方是否已经将死黑方

题解

模拟将能走的4个点,判断这个点是否被红子杀

代码

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
using namespace std;
int Map1[][],Map2[][],Dead[][];//Map1原来的棋盘,2将移动后的棋盘
void Up1(int x,int y)//帅
{
for(int i=x-;i>=;i--)//往上找
{
if(Map2[i][y]>=)//遇到阻拦
break;
Dead[i][y]=;//帅杀死的区域
}
}
void Up2(int x,int y)//车
{
for(int i=x-;i>=;i--)//往上找
{
if(Map2[i][y]>=)//遇到阻拦
break;
Dead[i][y]=;//车杀死
}
for(int i=x+;i<=;i++)//下
{
if(Map2[i][y]>=)
break;
Dead[i][y]=;
}
for(int j=y-;j>=;j--)//左
{
if(Map2[x][j]>=)
break;
Dead[x][j]=;
}
for(int j=y+;j<=;j++)//右
{
if(Map2[x][j]>=)
break;
Dead[x][j]=;
}
}
int dx[]={,,-,};//右,左,下,上
int dy[]={,-,,};
int ddx[]={-,,-,,-,-,,};
int ddy[]={,,-,-,-,,-,};
bool bj3(int i,int j)//马边界
{
if(i>=&&i<=&&j>=&&j<=)
return true;
return false;
}
void Up3(int x,int y)//马
{
for(int i=;i<;i++)
{
//马脚
if(Map2[x+dx[i]][y+dy[i]]>=)continue;
//马杀死
if(bj3(x+ddx[*i],y+ddy[*i]))Dead[x+ddx[*i]][y+ddy[*i]]=;
if(bj3(x+ddx[*i+],y+ddy[*i+]))Dead[x+ddx[*i+]][y+ddy[*i+]]=; }
}
void Up4(int x,int y)//跑
{
int F=;
for(int i=x-;i>=;i--)//上
{
if(Map2[i][y]>=)
F++;
if(F==)//架炮
Dead[i][y]=;
if(F==)//阻拦
break;
}
F=;
for(int i=x+;i<=;i++)//下
{
if(Map2[i][y]>=)
F++;
if(F==)
Dead[i][y]=;
if(F==)
break;
}
F=;
for(int j=y-;j>=;j--)//左
{
if(Map2[x][j]>=)
F++;
if(F==)
Dead[x][j]=;
if(F==)
break;
}
F=;
for(int j=y+;j<=;j++)//右
{
if(Map2[x][j]>=)
F++;
if(F==)
Dead[x][j]=;
if(F==)
break;
}
}
bool bj(int i,int j)//将边界
{
if(<=i&&i<=&&<=j&&j<=)
return true;
return false;
}
void Clear()
{
for(int i=;i<=;i++)
for(int j=;j<=;j++)
Map2[i][j]=Map1[i][j],Dead[i][j]=;
}
void Updata()
{
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(Map2[i][j]==)//帅
Up1(i,j);
if(Map2[i][j]==)//车
Up2(i,j);
if(Map2[i][j]==)//马
Up3(i,j);
if(Map2[i][j]==)//炮
Up4(i,j);
}
}
}
int main()
{
int n,a,b,hx,hy,gx,gy;
char c;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d%d%d",&n,&hx,&hy)!=EOF,n||hx||hy)
{
memset(Map1,,sizeof(Map1));
for(int i=;i<=n;i++)
{
c=getchar();
while(c==' ')c=getchar();//不加会错,估计卡空格了
scanf("%c %d %d",&c,&a,&b);
if(c=='G')//帅
Map1[a][b]=,gx=a,gy=b;
if(c=='R')//车
Map1[a][b]=;
if(c=='H')//马
Map1[a][b]=;
if(c=='C')//炮
Map1[a][b]=;
}
int win=;
//黑方直接飞将杀死红方(TOJ上是不考虑,其他平台要考虑)
//题意没说清,按残局来说的话这样毫无意义
/*
if(hy==gy)
{
int F=1;
for(int i=gx-1;i>=hx;i--)
{
if(Map1[i][gy]>=1)
{
F=0;break;
}
}
if(F)
{
printf("NO\n");
continue;
}
}
*/
for(int i=;i<;i++)
{
if(!bj(hx+dx[i],hy+dy[i]))continue;
Clear();
Map2[hx+dx[i]][hy+dy[i]]=;//吃子
Updata();
if(Dead[hx+dx[i]][hy+dy[i]])
{
win=;break;
}
}
if(win)printf("YES\n");
else printf("NO\n");
}
return ;
}

TZOJ 4746 Xiangqi(模拟棋盘数组)的更多相关文章

  1. TZOJ 4813 机器翻译(模拟数组头和尾)

    描述 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英文单词,软件会先在内存中查找这 ...

  2. uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列

    题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...

  3. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  4. Clumsy Keke【模拟+三维数组】

    Clumsy Keke 题目链接(点击) Problem Description Keke is currently studying engineering drawing courses, and ...

  5. JS模拟实现数组的map方法

    昨天使用map方法的时候,突然感觉一直在直接用,也没有试试是怎么实现的,本来想直接搜一篇文章盘一下子,结果没搜到合适的,好吧,那就自己来写一下子吧 今天就来实现一个简单的map方法 首先我们来看一下m ...

  6. Codeforces 798C. Mike and gcd problem 模拟构造 数组gcd大于1

    C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: s ...

  7. TZOJ 5280 搜索引擎(模拟字符串)

    描述 谷歌.百度等搜索引擎已经成为了互连网中不可或缺的一部分.在本题中,你的任务也是设计一个搜索论文的搜索引擎,当然,本题的要求比起实际的需求要少了许多. 本题的输入将首先给出一系列的论文,对于每篇论 ...

  8. ACM-ICPC北京赛区(2017)网络赛1【模拟+枚举+数组操作】

    题目1 : Visiting Peking University 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Ming is going to travel for n ...

  9. hdu4121 poj4001 Xiangqi(模拟)

    模拟题考验coding能力,一定要思路清晰,按照模块化思想,有哪些情况,需要哪些功能都要事先分析好了.高手的模拟题代码往往结构很清晰,功能模块写成函数,没有过多重复代码,让人一看便明. 方法选择的好坏 ...

随机推荐

  1. [转]将字体嵌入程序资源中 C# Winform

    http://social.msdn.microsoft.com/Forums/officeapps/zh-CN/61b717ae-f925-443a-baad-2b85f2564826/cwinfo ...

  2. mysql 不同事务隔离级别

    repeatable read 在同一事务中,同一查询多次进行时候,由于其他插入操作(insert)的事务提交,导致每次返回不同的结果集. 标准的repeatable read是允许幻读的,因为这一级 ...

  3. Vcenter5.5+vmwarePowercli6.5+powershell5批量创建虚拟机

    另存为xxx.ps1 ##########################通过模版批量部署虚拟机以下内容需要人工定义变量####################### #Vcenter的IP $vce ...

  4. 一个关于考勤统计的sql研究

    在这里,我们要做一个简单的员工考勤记录查询系统的后台数据库.业务需求如下所示:      1.统计每天来的最早.来的最晚.走的最早.走得最晚的人的姓名           1.1 统计每天来得最早的人 ...

  5. JQUERY dialog的用法详细解析

    本篇文章主要是对JQUERY中dialog的用法进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助 今天用到了客户端的对话框,把 jQuery UI 中的对话框学习了一下. 准备 jQ ...

  6. google浏览器清除缓存

    google浏览器设置不缓存的方法 摘要:我们在做web开发的时候特别是在调试js时,会经常使用的google浏览器,这个时候就要我们修改过的代码可能不能生效.这是因为我们的浏览器默认是有缓存的,但是 ...

  7. 理解 tornado.gen

    转自:http://blog.xiaogaozi.org/2012/09/21/understanding-tornado-dot-gen/ 理解 tornado.gen SEP 21ST, 2012 ...

  8. python实现定时发送系列

    1.发送邮件实现 2.定时任务实现 3.定时发送邮件实现 4.微信定时发送信息 详细源代码见:https://github.com/15387062910/timing_send 参考: 廖雪峰博客 ...

  9. J2SE 8的Lambda --- functions

    functions //1. Runnable 输入参数:无 返回类型void new Thread(() -> System.out.println("In Java8!" ...

  10. 机器学习入门-线性判别分析(LDA)1.LabelEncoder(进行标签的数字映射) 2.LinearDiscriminantAnalysis (sklearn的LDA模块)

    1.from sklearn.processing import LabelEncoder 进行标签的代码编译 首先需要通过model.fit 进行预编译,然后使用transform进行实际编译 2. ...