HDU 4121 Xiangqi 模拟题
Xiangqi
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=4121
Description
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
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 模拟题的更多相关文章
- HDU 4121 Xiangqi --模拟
题意: 给一个象棋局势,问黑棋是否死棋了,黑棋只有一个将,红棋可能有2~7个棋,分别可能是车,马,炮以及帅. 解法: 开始写法是对每个棋子,都处理处他能吃的地方,赋为-1,然后判断将能不能走到非-1的 ...
- HDU 4121 Xiangqi (算是模拟吧)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4121 题意:中国象棋对决,黑棋只有一个将,红棋有一个帅和不定个车 马 炮冰给定位置,这时当黑棋走,问你黑 ...
- HDU 4121 Xiangqi
模拟吧,算是... 被这个题wa到哭,真是什么都不想说了...上代码 #include <iostream> #include <cstring> using namespac ...
- HDU 4121 Xiangqi 我老了?
Xiangqi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- HDU 4431 Mahjong(模拟题)
题目链接 写了俩小时+把....有一种情况写的时候漏了...代码还算清晰把,想了很久才开写的. #include <cstdio> #include <cstring> #in ...
- HDU 1234 简单模拟题
题目很简单不多说了,我只是觉得这题目的输入方式还是很有特点的 #include <cstdio> #include <cstring> #include <algorit ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4452 Running Rabbits (模拟题)
题意: 有两只兔子,一只在左上角,一只在右上角,两只兔子有自己的移动速度(每小时),和初始移动方向. 现在有3种可能让他们转向:撞墙:移动过程中撞墙,掉头走未完成的路. 相碰: 两只兔子在K点整(即处 ...
- hdu 5641 King's Phone(暴力模拟题)
Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...
随机推荐
- 一天一个Java基础——反射
1.概念 反射主要是指程序可以访问,检测和修改它本身的状态或行为的一种能力 Java中的反射是一种强大的工具,它能够创建灵活的代码,这些代码可以运行时装配,无须在组件之间进行链接 反射允许在编写与执行 ...
- 【Java集合框架】规则集--Set
集合: Java主要支持三种: 1.规则集(Set) 用于存储一组不重复的元素 2.线性表(List) 用于存储一个由元素构成的有序集合 3.队列(Queue) 同与数据结构中的队列,存储用先进先出的 ...
- 【转】Linux 之 /etc/profile、~/.bash_profile 等几个文件的执行过程
原文网址:http://blog.csdn.net/ithomer/article/details/6322892 在登录Linux时要执行文件的过程如下:在刚登录Linux时,首先启动 /etc/p ...
- 顶 企业站常用css横向导航菜单
<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/T ...
- 阿里云容器服务--配置自定义路由服务应对DDOS攻击
阿里云容器服务--配置自定义路由服务应对DDOS攻击 摘要: 容器服务中,除了slb之外,自定义路由服务(基于HAProxy)也可以作为DDOS攻击的一道防线,本文阐述了几种方法来应对普通规模的DDO ...
- Ch04-文字列表的设计
Ch04: 文字列表的设计 4.1 编号列表 语法: <OL> <li>编号1 <li>编号2 ...... </OL> 属性: 编号类型:type=1 ...
- Hadoop集群中Hbase的介绍、安装、使用
导读 HBase – Hadoop Database,是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBase技术可在廉价PC Server上搭建起大规模结构化存储集群. 一.Hbase ...
- The Bookcase
题意: 有n本宽w高h的书,向三层书架上放,每层不能为空,求占用的整体的最小面积(总高度*三层中最宽的) 分析: 不太好想,dp[i][j]表示第一层宽度为i第二层为j放的最小高度 dp[i][j]= ...
- OpenGL超级宝典第5版&&开发环境搭建
参考:http://www.zyh1690.org/build-opengl-super-bible-fifth-edition-development-environment/ 环境搭建的测试环境为 ...
- codeforce 702E Analysis of Pathes in Functional Graph RMQ+二进制
http://codeforces.com/contest/702 题意:n个点,n条边,每个点出边只有一条,问从每个点出发经过k条边的边权和,以及边权最小值 思路: f[i][j] 第i个点出发,经 ...