[HDOJ4121]Xiangqi(模拟)

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4121

题意:象棋棋盘上有一方只有车马炮帅,另一方只有将,现在轮到将走,问是不是被将死了。

枚举所有被车马炮帅覆盖的位置,看看将还能不能有不被覆盖的地方走。这个题写起来好麻烦啊…

  1 /*
  2 ━━━━━┒ギリギリ♂ eye!
  3 ┓┏┓┏┓┃キリキリ♂ mind!
  4 ┛┗┛┗┛┃\○/
  5 ┓┏┓┏┓┃ /
  6 ┛┗┛┗┛┃ノ)
  7 ┓┏┓┏┓┃
  8 ┛┗┛┗┛┃
  9 ┓┏┓┏┓┃
 10 ┛┗┛┗┛┃
 11 ┓┏┓┏┓┃
 12 ┛┗┛┗┛┃
 13 ┓┏┓┏┓┃
 14 ┃┃┃┃┃┃
 15 ┻┻┻┻┻┻
 16 */
 17 #include <algorithm>
 18 #include <iostream>
 19 #include <iomanip>
 20 #include <cstring>
 21 #include <climits>
 22 #include <complex>
 23 #include <fstream>
 24 #include <cassert>
 25 #include <cstdio>
 26 #include <bitset>
 27 #include <vector>
 28 #include <deque>
 29 #include <queue>
 30 #include <stack>
 31 #include <ctime>
 32 #include <set>
 33 #include <map>
 34 #include <cmath>
 35 using namespace std;
 36 #define fr first
 37 #define sc second
 38 #define cl clear
 39 #define BUG puts("here!!!")
 40 #define W(a) while(a--)
 41 #define pb(a) push_back(a)
 42 #define Rint(a) scanf("%d", &a)
 43 #define Rll(a) scanf("%I64d", &a)
 44 #define Rs(a) scanf("%s", a)
 45 #define Cin(a) cin >> a
 46 #define FRead() freopen("in", "r", stdin)
 47 #define FWrite() freopen("out", "w", stdout)
 48 #define Rep(i, len) for(int i = 0; i < (len); i++)
 49 #define For(i, a, len) for(int i = (a); i < (len); i++)
 50 #define Cls(a) memset((a), 0, sizeof(a))
 51 #define Clr(a, x) memset((a), (x), sizeof(a))
 52 #define Full(a) memset((a), 0x7f7f7f, sizeof(a))
 53 #define lrt rt << 1
 54 #define rrt rt << 1 | 1
 55 #define pi 3.14159265359
 56 #define RT return
 57 #define lowbit(x) x & (-x)
 58 #define onecnt(x) __builtin_popcount(x)
 59 typedef long long LL;
 60 typedef long double LD;
 61 typedef unsigned long long ULL;
 62 typedef pair<int, int> pii;
 63 typedef pair<string, int> psi;
 64 typedef pair<LL, LL> pll;
 65 typedef map<string, int> msi;
 66 typedef vector<int> vi;
 67 typedef vector<LL> vl;
 68 typedef vector<vl> vvl;
 69 typedef vector<bool> vb;
 70
 71 const int maxn = 18;
 72 char G[maxn][maxn], chess[maxn][maxn];
 73 int n, bgx, bgy;
 74 vector<pii> pos;
 75 char tp[5];
 76 int dx[5] = {-1, 0, 1, 0};
 77 int dy[5] = {0, 1, 0, -1};
 78 int dir[9][2] = {
 79     {-2,-1},{-2,1},{-1,2},{1,2},
 80   {2,-1},{2,1},{-1,-2},{1,-2}
 81 };
 82
 83 bool ok(int x, int y) {
 84   if(x >= 1 && x <= 10 && y >= 1 && y <= 10) return 1;
 85   return 0;
 86 }
 87
 88 void go(int x, int y) {
 89     int tx, ty;
 90     if(chess[x][y] == ‘G‘) {
 91         tx = x - 1;
 92         while(tx > 0 && chess[tx][y] == 0) G[tx--][y] = 0;
 93         if(tx > 0) G[tx][y] = 0;
 94     }
 95     else if(chess[x][y] == ‘H‘) {
 96         Rep(i, 8) {
 97             tx = x + dir[i][0];
 98             ty = y + dir[i][1];
 99             if(ok(tx, ty) && !chess[dx[i>>1]+x][dy[i>>1]+y]) {
100                 G[tx][ty] = 0;
101             }
102         }
103     }
104     else if(chess[x][y] == ‘C‘) {
105         Rep(i, 4) {
106             tx = x + dx[i];
107             ty = y + dy[i];
108             while(ok(tx, ty) && chess[tx][ty] == 0) {
109                 tx += dx[i];
110                 ty += dy[i];
111             }
112             tx += dx[i];
113             ty += dy[i];
114             while(ok(tx, ty) && chess[tx][ty] == 0) {
115                 G[tx][ty] = 0;
116                 tx += dx[i];
117                 ty += dy[i];
118             }
119         }
120     }
121     else if(chess[x][y] == ‘R‘) {
122         Rep(i, 4) {
123             tx = x + dx[i];
124             ty = y + dy[i];
125             while(ok(tx, ty) && chess[tx][ty] == 0) {
126                 G[tx][ty] = 0;
127                 tx += dx[i];
128                 ty += dy[i];
129             }
130             if(ok(tx, ty)) G[tx][ty] = 0;
131         }
132     }
133 }
134
135 int main() {
136     // FRead();
137     int x, y;
138     while(~scanf("%d%d%d",&n,&bgx,&bgy) && n+bgx+bgy) {
139         Clr(G, -1); Cls(chess); pos.clear();
140         Rep(i, n) {
141             Rs(tp); Rint(x); Rint(y);
142             pos.push_back(pii(x, y));
143             chess[x][y] = tp[0];
144         }
145         Rep(i, pos.size()) go(pos[i].first, pos[i].second);
146         int flag = 0;
147         if(G[bgx][bgy]) flag = 1;
148         Rep(i, 4) {
149             x = bgx + dx[i];
150             y = bgy + dy[i];
151             if(x >= 1 && x <= 3 && y >= 4 && y <= 6 && G[x][y]) flag = 1;
152         }
153         if(!flag) puts("YES");
154         else puts("NO");
155     }
156     RT 0;
157 }
时间: 2024-10-01 03:08:59

[HDOJ4121]Xiangqi(模拟)的相关文章

HDU 4121 Xiangqi 模拟

原题: http://acm.hdu.edu.cn/showproblem.php? pid=4121 题目: Xiangqi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4809 Accepted Submission(s): 1134 Problem Description Xiangqi is one of the most pop

UVa 1589 Xiangqi(模拟 HDU4121)

题意  给你一个黑方被将军的象棋残局  判断红方是否已经把黑方将死 模拟题  注意细节就行了  看黑方的将是否四个方向都不能走 #include<cstdio> #include<cstring> using namespace std; const int N = 12; char brd[N][N]; int dx[] = { -1, 1, 0, 0}, dy[] = {0, 0, -1, 1}; int hx[] = { -2, -1, -2, -1, 1, 2, 1, 2}

hdu4121 poj4001 Xiangqi(模拟)

模拟题考验coding能力,一定要思路清晰,按照模块化思想,有哪些情况,需要哪些功能都要事先分析好了.高手的模拟题代码往往结构很清晰,功能模块写成函数,没有过多重复代码,让人一看便明. 方法选择的好坏会影响编程复杂度,这题老将最多只能往四个位置走,就枚举这四个位置,每个位置再枚举每个红子看是不是有子能吃了它.枚举时注意有可能老将这一步吃了一个红子. 有一种情况是一开始双方老将就见面,这其实不叫红棋在将军,实际中红棋不能这么将.但是毕竟是一道编程题,出题人可能也不是太懂棋...所以要考虑这种情况.

UVA - 1589 Xiangqi (模拟)

Xiangqi 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

UVA 1589:Xiangqi (模拟 Grade D)

题目: 象棋,黑棋只有将,红棋有帅车马炮.问是否死将. 思路: 对方将四个方向走一步,看看会不会被吃. 代码: 很难看……WA了很多发,还越界等等. #include <cstdio> #include <cstring> #include <cstdlib> char graph[13][13]; int go[4][2] = {{1,0},{0,1},{-1,0},{0,-1}}; bool inBlackPalace(int x, int y) { return

Xiangqi(比较复杂的模拟)

4746: Xiangqi 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 总提交: 15            测试通过:2 描述 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 "gen

poj 4001 Xiangqi(模拟)

Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1357   Accepted: 347 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 e

UVA 1589 Xiangqi(仔细的模拟)

题意:中国象棋大家都玩过,就是基本规则,只有将,帅,车,马,炮. 解题思路: 思路是把各个棋子能攻击到的位置在judge数组相应的位置上标记出来 首先考虑马蹩马腿的情况,这个比较好考虑,注意不要越界就行了. 车,不能穿过自己方的车,马,炮,帅.但范围可以穿过'将',因为'将'下一步会移动. 炮,不可以用'将'作为炮架,其余都可以,因为'将'下一步会移动. 帅,情况很简单.一条线. 要注意的是,每个棋子的攻击范围,是必须到另一个棋子的位置的 考虑数据 3 1 5 R 1 1 R 2 5 G10 5

POJ Xiangqi 4001 &amp;&amp; HDOJ 4121 Xiangqi

题目链接(POJ):http://poj.org/problem?id=4001 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=4121 Xiangqi Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1108   Accepted: 299 Description Xiangqi is one of the most popular two-player boa