• [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 }
  • 相关阅读:
    40个Java集合面试问题和答案
    jsp九大内置对象:request、response、session、application、out、page、pageContext、config、exception
    JAVA多线程和并发基础面试问答
    线程的五大状态
    人物与动物快速抠图技巧
    实时监听数据库变化
    inter jion与WITH (NOLOCK) 排他锁(脏读)
    Win定时任务未正常运行的bug(win Server2019)
    HttpWebRequest与HttpWebResponse的关系
    A5M2 sql自动换行快捷键
  • 原文地址:https://www.cnblogs.com/kirai/p/5803614.html
Copyright © 2020-2023  润新知