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 ...
随机推荐
- TCP/IP详解学习笔记(3)-IP协议,ARP协议,RARP协议
把这三个协议放到一起学习是因为这三个协议处于同一层,ARP协议用来找到目标主机的Ethernet网卡Mac地址,IP则承载要发送的消息.数据链路层可以从ARP得到数据的传送信息,而从IP得到要传输的数 ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- BLOCK专题
>>定义并使用一个block 返回值(^名字)(参数列表) =^返回值类型(参数列表){表达式}; 其中返回值和参数列表可以神略 ,最简单的block是 ^{xxxx}; voi ...
- duilib入门之贴图描述、类html文本描述、动态换肤、Dll插件、资源打包
转载自duilib入门文档 贴图描述: Duilib的表现力丰富很大程度上得益于贴图描述的简单强大.Duilib的贴图描述分为简单模式和复杂模式两种. 简单模式使用文件名做为贴图描述内容,在这种方式下 ...
- SQL遍历字符串的方法
字符串穿越: 1.创建一个只存递增序列(1…n)的表——Temp,并将它与目标字符串所在的表Src进行笛卡尔运算.(Temp表的记录数要不小于遍历的目标字符串的长度) 2.过滤掉序列值大于串长的行. ...
- andriod的简单用法1
1.从一个Activity跳转到另一个Activity,使用Intent. 在按钮的onClick中如下写法: public void Login(View view) { Intent intent ...
- mysql操作时遇到的小问题
mysql数据库在程序中执行sql语句时,或者在执行sql时,数据库表可能会有一些特殊的字符,比如说#,.等,这样在执行时 可能会遇到问题 如以下的表名,backup_2014.2.22, 这个表在查 ...
- bzoj 3218 a + b Problem(最小割+主席树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3218 [题意] 给n个格子涂白或黑色,白则wi,黑则bi的好看度,若黑格i存在: 1& ...
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
UVa11995 I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...
- Tkinter教程之Canvas篇(2)
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811888 '''Tkinter教程之Canvas篇(2)''''''9.创建item的tag ...