题目链接

Problem 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


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.

AC

  • 细心模拟题
  • 先把红方的棋读进来,然后每个棋子的杀伤范围,最后判断黑将能否移动
  • 如果一直WA就好好debug去吧。。。
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <map>
#include <bitset>
#include <set>
#include <string.h>
#include <cmath>
#include <queue>
#include <algorithm>
#define N 100005
#define P pair<int,int>
#define ll long long
#define lowbit(a) a&(-a)
#define mk(a, b) make_pair(a, b)
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
char a[100][100];
int vis[100][100];
// 将红帅的杀伤标记
void cG(int x, int y) {for (int i = x - 1; i >= 1; --i) {vis[i][y] = 1;if (a[i][y] != '0') break;}return;
}// 将车的杀伤标记
void cR(int x, int y) {// 右 for (int i = y + 1; i <= 9; ++i) {vis[x][i] = 1;if (a[x][i] != '0') break;}// 下 for (int i = x + 1; i <= 10; ++i) {vis[i][y] = 1;if (a[i][y] != '0') break;}// 左 for (int i = y - 1; i >= 1; --i) {vis[x][i] = 1;if (a[x][i] != '0') break;}// 上 for (int i = x - 1; i >= 1; --i) {vis[i][y] = 1;if (a[i][y] != '0') break;}return;
}
// 判断马的杀伤是否合法
bool judge(int x, int y) {if (x >= 1 && x <= 10 && y >= 1 && y <= 9)return true;elsereturn false;
}
void cH(int x, int y) {int xx , yy;// 1xx = x - 2;yy = y - 1;if (judge(xx, yy) && judge(x - 1, y) && a[x - 1][y] == '0') {vis[xx][yy] = 1;}yy = y + 1; if (judge(xx, yy) && judge(x - 1, y) && a[x - 1][y] == '0') {vis[xx][yy] = 1;}// 2xx = x - 1;yy = y - 2;if (judge(xx, yy) && judge(x , y - 1) && a[x][y - 1] == '0') {vis[xx][yy] = 1;}yy = y + 2;if (judge(xx, yy) && judge(x , y + 1) && a[x][y + 1] == '0') {vis[xx][yy] = 1;}// 3xx = x + 1;yy = y - 2;if (judge(xx, yy) && judge(x , y - 1) && a[x][y - 1] == '0') {vis[xx][yy] = 1;}yy = y + 2;if (judge(xx, yy) && judge(x , y + 1) && a[x][y + 1] == '0') {vis[xx][yy] = 1;}// 4xx = x + 2;yy = y - 1;if (judge(xx, yy) && judge(x + 1 , y) && a[x + 1][y] == '0') {vis[xx][yy] = 1;}yy = y + 1;if (judge(xx, yy) && judge(x + 1 , y ) && a[x + 1][y] == '0') {vis[xx][yy] = 1;}
}
// 将炮的杀伤标记
void cC(int x, int y) {// 右 for (int i = y + 1; i <= 9; ++i) {if (a[x][i] != '0') {for (int j = i + 1; j <= 9; ++j) {vis[x][j] = 1;if (a[x][j] != '0')break;}break;}}// 下 for (int i = x + 1; i <= 10; ++i) {if (a[i][y] != '0') {for (int j = i + 1; j <= 10; ++j) {vis[j][y] = 1;if (a[j][y] != '0')break;}break;}}// 左 for (int i = y - 1; i >= 1; --i) {if (a[x][i] != '0') {for (int j = i - 1; j >= 1; --j) {vis[x][j] = 1;if (a[x][j] != '0')break;}break;}}// 上 for (int i = x - 1; i >= 1; --i) {if (a[i][y] != '0') {for (int j = i - 1; j >= 1; --j) {vis[j][y] = 1;if (a[j][y] != '0')break;}break;}}return;
}
// 判断黑将的位置是否合法
bool judgeG(int x, int y) {if (x >= 1 && x <= 3 && y <= 6 && y >= 4)return true;elsereturn false;
}
// 判断黑将4个方向时候可以走
bool judge_ans(int x, int y) {if (judgeG(x + 1, y) && vis[x + 1][y] == 0)return true;    if (judgeG(x - 1, y) && vis[x - 1][y] == 0)return true;if (judgeG(x , y + 1) && vis[x][y + 1] == 0)return true;if (judgeG(x , y - 1) && vis[x][y - 1] == 0)return true;return false;
}int main(){
#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);
#endifint n, xx, yy;while (cin >> n >> xx >> yy, n + xx + yy) {char c;int x, y;// 0 表示没有棋子,可以走 mem(a, '0');// 0 表示可以走 mem(vis, 0);for (int i = 0; i < n; ++i) {cin >> c >> x >> y;a[x][y] = c;}for (int i = 10; i >= 1; --i) {for (int j = 1; j <= 9; ++j) {if (a[i][j] == 'C') {cC(i, j);}if (a[i][j] == 'R') {cR(i, j);}if (a[i][j] == 'G') {cG(i, j);}if (a[i][j] == 'H') {cH(i, j);}}}if (judge_ans(xx, yy))cout << "NO\n";else cout << "YES\n";}
#ifndef ONLINE_JUDGEfclose(stdin);
#endif      return 0;
}

HDU 4121 Xiangqi相关推荐

  1. HDU 4121 Xiangqi 模拟题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=4121 首先对标题赞一个,非要叫 "Xiangqi" 而不是 "中国象棋&q ...

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

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

  3. HDU 4121 Xiangqi --模拟

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

  4. android封装浏览器,android利用WebView实现浏览器的封装

    android提供了封装浏览器的接口,可以让开发者利用自己的view显示网页内容.今天又实现研究了一下,利用WebView显示浏览器内容,还可以利用 WebViewClient显示自己需要的内容. 效 ...

  5. HDU - 4461 The Power of Xiangqi

    题目链接 题意 给你两个人的象棋棋子,每个棋子对应一个防御值,如果一个人跑和马不全的话防御值减1.计算那个人的防御最高. AC #include <iostream> #include & ...

  6. 《算法竞赛入门经典》 习题 4-1 (Xiangqi, ACM/ICPC Fuzhou 2011, UVa1589,hdoj_4121)

    原题: [hdoj链接](http://acm.hdu.edu.cn/showproblem.php?pid=4121) Problem Description Xiangqi is one of t ...

  7. 象棋 (Xiangqi, ACM/ICPC Fuzhou 2011, UVa1589)

    Description Xiangqi is one of the most popular two-player board games in China. The game represents ...

  8. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  9. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

最新文章

  1. 叛乱联机服务器未响应,叛乱沙漠风暴怎么开服 叛乱沙漠风暴开服操作指南详解 安装准备-游侠网...
  2. Eclipse基金会发布Eclipse Photon IDE
  3. 牛妹吃豆子(二维前缀和模板,修改+求和)
  4. KVM 网络虚拟化基础 - 每天5分钟玩转 OpenStack(9)
  5. buu [AFCTF2018]Morse
  6. 用netsh自动切换IP
  7. 万用表检测常用元器件的方法
  8. leetcode104. 二叉树的最大深度(层序遍历09)
  9. MYSQL中什么是规范化_如何规范化SQL数据库
  10. 5年财务老员工:早发现这个报表工具,也不会因为加班凄凉辞职
  11. 数据结构与算法-黑盒与白盒测试法
  12. 400 fps!CenterFace+TensorRT部署人脸和关键点检测
  13. [Iphone开发]如何在GDB中查看变量的值
  14. python怎么批量下载图片_python批量下载图片的三种方法
  15. c++ 智能指针auto_ptr (c++98)、shared_ptr(c++ 11)、unique_ptr(c++ 11)、weak_ptr(c++ 11)
  16. java 短链跳转原理_短连接跳转的原理
  17. 一般家用路由器买多大的合适_家用路由器多少兆合适
  18. 滕振宇谈如何进行单元测试
  19. Stimulsoft 仪表板.JS 2022.2.1
  20. mac游戏排行榜,mac好玩的游戏推荐 (一)

热门文章

  1. 博客作业——创建个人技术博客(建议在cnblogs.com上创建),并写一个自我介绍,列出你对这门课的希望和自己的目标。同时具体列出你计划每周花多少时间在这门课上(包括上课时间)。...
  2. 关于网络流sap算法
  3. iOS开发之时间格式的转化
  4. lightoj 1004 dp:数字三角形
  5. SqlHelper数据库操作辅助类
  6. java中同步_在Java中的方法同步和语句同步(块同步) - Break易站
  7. [数据库] Navicat for Oracle设置唯一性和递增序列实验
  8. [Android] 触屏setOnTouchListener实现图片缩放、移动、绘制和添加水印
  9. 【数据结构与算法】之深入解析“验证IP地址”的求解思路与算法示例
  10. Python之值得学习练手的22个迷你程序(附代码)