Xiangqi

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4121

Description

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

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

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

题意

给你一个象棋残局,黑方只剩下一个王了。现在该王走了,是否王怎么走都会死了?

题解:

1.黑方王在走的时候,可以踩死红方棋子

2.马会被蹩脚

然后没有什么坑点了,暴力模拟就好了……

代码

#include<iostream>
#include<stdio.h>
#include<vector>
#include<cstring>
using namespace std; int n,x,y;
vector<pair<int,int> >P;
vector<pair<int,int> >H;
vector<pair<int,int> >C;
vector<pair<int,int> >G;
int dx[]={,-,,};
int dy[]={,,,-};
int vis[][];
void init()
{
P.clear();
H.clear();
C.clear();
G.clear();
memset(vis,,sizeof(vis));
}
int check(int xx,int yy)
{
//cout<<xx<<" "<<yy<<endl;
if(xx<||xx>)return ;
if(yy<||yy>)return ; for(int i=;i<C.size();i++)
{
int xxx = C[i].first, yyy = C[i].second;
if(xxx == xx && yyy == yy)
continue;
while(xxx<=)
{
xxx++;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
xxx = C[i].first, yyy = C[i].second;
while(xxx)
{
xxx--;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
xxx = C[i].first, yyy = C[i].second;
while(yyy<=)
{
yyy++;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
xxx = C[i].first, yyy = C[i].second;
while(yyy)
{
yyy--;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
}
//cout<<xx<<" "<<yy<<endl;
for(int i=;i<H.size();i++)
{
int xxx = H[i].first , yyy = H[i].second;
if(xxx == xx && yyy == yy)
continue;
if(xxx != && vis[xxx-][yyy]==)
{
if(xx == xxx - && yy == yyy + )
return ;
if(xx == xxx - && yy == yyy - )
return ;
}
if(xxx != && vis[xxx+][yyy]==)
{
if(xx == xxx + && yy == yyy + )
return ;
if(xx == xxx + && yy == yyy - )
return ;
}
if(yyy != && vis[xxx][yyy-]==)
{
if(xx == xxx + && yy == yyy - )
return ;
if(xx == xxx - && yy == yyy - )
return ;
}
if(yyy != && vis[xxx][yyy+]==)
{
if(xx == xxx + && yy == yyy + )
return ;
if(xx == xxx - && yy == yyy + )
return ;
}
}
//cout<<xx<<" "<<yy<<endl;
for(int i=;i<P.size();i++)
{
int xxx = P[i].first,yyy = P[i].second;
if(xxx == xx && yyy == yy)
continue;
int flag = ;
while(xxx<=)
{
xxx++;
if(xxx == xx && yyy == yy && flag == )
return ;
if(vis[xxx][yyy])
flag++;
}
xxx = P[i].first, yyy = P[i].second,flag = ;
while(xxx)
{
xxx--;
if(xxx == xx && yyy == yy && flag == )
return ;
if(vis[xxx][yyy])
flag++;
}
xxx = P[i].first, yyy = P[i].second,flag = ;
while(yyy<=)
{
yyy++;
if(xxx == xx && yyy == yy && flag == )
return ;
if(vis[xxx][yyy])
flag++;
}
xxx = P[i].first, yyy = P[i].second,flag = ;
while(yyy)
{
yyy--;
if(xxx == xx && yyy == yy && flag == )
return ;
if(vis[xxx][yyy])
flag++;
}
} for(int i=;i<G.size();i++)
{
int xxx = G[i].first, yyy = G[i].second;
if(xxx == xx && yyy == yy)
continue;
while(xxx<=)
{
xxx++;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
xxx = G[i].first, yyy = G[i].second;
while(xxx)
{
xxx--;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
xxx = G[i].first, yyy = G[i].second;
while(yyy<=)
{
yyy++;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
xxx = G[i].first, yyy = G[i].second;
while(yyy)
{
yyy--;
if(xxx == xx && yyy == yy)
return ;
if(vis[xxx][yyy])
break;
}
}
//cout<<xx<<" "<<yy<<endl;
return ;
}
int main()
{
while(scanf("%d%d%d",&n,&x,&y)!=EOF)
{
if(n== && x == && y == )
break;
init();
string cc;int xx,yy;
for(int i=;i<n;i++)
{
cin>>cc;
scanf("%d %d",&xx,&yy);
if(cc[]=='G')
G.push_back(make_pair(xx,yy));
if(cc[]=='R')
C.push_back(make_pair(xx,yy));
if(cc[]=='H')
H.push_back(make_pair(xx,yy));
if(cc[]=='C')
P.push_back(make_pair(xx,yy));
vis[xx][yy]++;
} xx = x,yy = y;
int flag2 = ;
for(int i=;i<G.size();i++)
{
int xxx = G[i].first, yyy = G[i].second;
if(xxx == xx && yyy == yy)
continue;
while(xxx<=)
{
xxx++;
if(xxx == xx && yyy == yy)
flag2 = ;
if(vis[xxx][yyy])
break;
}
xxx = G[i].first, yyy = G[i].second;
while(xxx)
{
xxx--;
if(xxx == xx && yyy == yy)
flag2 = ;
if(vis[xxx][yyy])
break;
}
xxx = G[i].first, yyy = G[i].second;
while(yyy<=)
{
yyy++;
if(xxx == xx && yyy == yy)
flag2 = ;
if(vis[xxx][yyy])
break;
}
xxx = G[i].first, yyy = G[i].second;
while(yyy)
{
yyy--;
if(xxx == xx && yyy == yy)
flag2 = ;
if(vis[xxx][yyy])
break;
}
}
if(flag2)
{
printf("NO\n");
continue;
}
int flag = ;
for(int i=;i<;i++)
{
xx = x + dx[i];
yy = y + dy[i];
vis[xx][yy]++;
if(!check(xx,yy))
flag ++;
vis[xx][yy]--;
}
if(flag == )
printf("YES\n");
else
printf("NO\n");
}
}

HDU 4121 Xiangqi 模拟题的更多相关文章

  1. HDU 4121 Xiangqi --模拟

    题意: 给一个象棋局势,问黑棋是否死棋了,黑棋只有一个将,红棋可能有2~7个棋,分别可能是车,马,炮以及帅. 解法: 开始写法是对每个棋子,都处理处他能吃的地方,赋为-1,然后判断将能不能走到非-1的 ...

  2. HDU 4121 Xiangqi (算是模拟吧)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4121 题意:中国象棋对决,黑棋只有一个将,红棋有一个帅和不定个车 马 炮冰给定位置,这时当黑棋走,问你黑 ...

  3. HDU 4121 Xiangqi

    模拟吧,算是... 被这个题wa到哭,真是什么都不想说了...上代码 #include <iostream> #include <cstring> using namespac ...

  4. HDU 4121 Xiangqi 我老了?

    Xiangqi Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. HDU 4431 Mahjong(模拟题)

    题目链接 写了俩小时+把....有一种情况写的时候漏了...代码还算清晰把,想了很久才开写的. #include <cstdio> #include <cstring> #in ...

  6. HDU 1234 简单模拟题

    题目很简单不多说了,我只是觉得这题目的输入方式还是很有特点的 #include <cstdio> #include <cstring> #include <algorit ...

  7. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  8. HDU 4452 Running Rabbits (模拟题)

    题意: 有两只兔子,一只在左上角,一只在右上角,两只兔子有自己的移动速度(每小时),和初始移动方向. 现在有3种可能让他们转向:撞墙:移动过程中撞墙,掉头走未完成的路. 相碰: 两只兔子在K点整(即处 ...

  9. hdu 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

随机推荐

  1. w3c盒子模型与ie盒子模型

    盒子模型是css的专有名词,用来描述页面设置中的各种属性,如内容(content).填充(padding).边框(border).边界(margin),由于这些属性拼在一起,与日常生活中的“盒子”很相 ...

  2. CSS HACK区别IE6、IE7、IE8、Firefox兼容性

    相信不少人,都特别清楚CSS HACK,而其中也是区别IE6.IE7.IE8.Firefox兼容性问题用的,CSS hack由于不同的浏览器,对CSS的解析认识不一样,因此会导致生成的页面效果不一样. ...

  3. 一步一步ITextSharp 低级操作函数使用

    首先说一下PDF文档的结构: 分为四层,第一层和第四层由低级操作来进行操作,第二层.第三层由高级对象操作 第一层操作只能使用PdfWriter.DirectContent操作,第四层使用DirectC ...

  4. UML类图设计

    大纲: 在Visio里,包和类的关系是包含关系,将类拖入包的文件夹之后,关系就建立了,二元关联符号可以设置为:聚合.合成.接口:空心圆+直线(唐老鸭类实现了‘讲人话’):依赖:虚线+箭头(动物和空气的 ...

  5. [Tommas] 一种有效的测试策略(转)

    在最近的一个大型项目中,我们在早期就定下了一个目标:不会在软件中使用大量QA人员专注于手工测试.通过手工测试发现bug极其耗时且成本高昂,这促使团队尝试尽可能的将质量内嵌到产品内部.但这并不意味着手工 ...

  6. Jacoco远程统计代码覆盖率

    Jacoco   什么是Jacoco? Jacoco是一个开源的Java代码覆盖率工具,Jacoco可以嵌入到Ant .Maven中,并提供了EclEmma Eclipse插件,也可以使用JavaAg ...

  7. IAR编译信息分析

    1.怎么设置可以查看单片的内存(消耗)使用状况? IAR的菜单栏 -->Tools -->IDE Options -->Messages -->Show build messa ...

  8. DataTable行转列

    /// <summary> /// DataTable行转列 /// </summary> /// <param name="dtable">需 ...

  9. PHP:产生不重复随机数的方法

    来源:http://www.ido321.com/1217.html 无论是Web应用,还是WAP或者移动应用,随机数都有其用武之地.在最近接触的几个小项目中,我也经常需要和随机数或者随机数组打交道, ...

  10. Apache Rewrite常用设置说明

    例子: RewriteEngine on 打开引擎 RewriteRule test.html /test.php [L] RewriteRule test.html?$ /tianqi.php?s1 ...