博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4121 模拟
阅读量:2444 次
发布时间:2019-05-10

本文共 4244 字,大约阅读时间需要 14 分钟。

/****************************************************************************************************    坑爹的模拟题~注意这两种情况:黑方的将能直接飞过去杀了红方的将,还有将走一步能把红方别的子给吃了。。。****************************************************************************************************/#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )#define CLR(x, k) memset((x), (k), sizeof(x))#define CPY(t, s) memcpy((t), (s), sizeof(s))#define SC(t, s) static_cast
(s)#define LEN(s) static_cast
( strlen((s)) )#define SZ(s) static_cast
( (s).size() )typedef double LF;//typedef long long LL; //GNU C++//typedef unsigned long long ULL;typedef __int64 LL; //Visual C++ 2010typedef unsigned __int64 ULL;typedef pair
PII;typedef pair
PLL;typedef pair
PDD;typedef map
::iterator MI;typedef vector
::iterator VI;typedef list
::iterator LI;typedef set
::iterator SI;template
T sqa(const T &x){ return x * x;}template
T gcd(T a, T b){ if (!a || !b) { return max(a, b); } T t; while (t = a % b) { a = b; b = t; } return b;}template
T ext_gcd(T a, T b, T &x, T &y){ if (!b) { x = 1; y = 0; return a; } T d = ext_gcd(b, a % b, x, y); T t = x; x = y; y = t - a / b * y; return d;}template
T invmod(T a, T p){ LL inv, y; ext_gcd(a, p, inv, y); inv < 0 ? inv += p : 0; return inv;}const int INF_INT = 0x3f3f3f3f;const LL INF_LL = 0x7fffffffffffffffLL; //15fconst double oo = 10e9;const double eps = 10e-7;const double PI = acos(-1.0);#define ONLINE_JUDGEconst int MAXN = 20;int n;struct Pos{ int x, y; Pos(){} Pos(int _x, int _y) { x = _x; y = _y; } bool operator == (const Pos &rhs) const { return rhs.x == x && rhs.y == y; }}bg, wg;int board[MAXN][MAXN];const int gDir[4][2] = { {0, -1}, {-1, 0}, {0, 1}, {1, 0} };const int hDir[8][2] = { {1, -2}, {-1, -2}, {-2, -1}, {-2, 1}, {-1, 2}, {1, 2}, {2, 1}, {2, -1} };bool inBoard(const Pos &p){ return 1 <= p.x && p.x <= 10 && 1 <= p.y && p.y <= 9;}bool inPalace(const Pos &p){ return 1 <= p.x && p.x <= 3 && 4 <= p.y && p.y <= 6;}int checkV(const Pos &pa, const Pos &pb){ if (pa.y != pb.y) { return -1; } int res = 0; for (int i = min(pa.x, pb.x) + 1; i <= max(pa.x, pb.x) - 1; ++i) { if (board[i][pa.y]) { ++res; } } return res;}int checkH(const Pos &pa, const Pos &pb){ if (pa.x != pb.x) { return -1; } int res = 0; for (int j = min(pa.y, pb.y) + 1; j <= max(pa.y, pb.y) - 1; ++j) { if (board[pa.x][j]) { ++res; } } return res;}bool canLive(const Pos &tg){ for (int x = 1; x <= 10; ++x) { for (int y = 1; y <= 9; ++y) { if (2 == board[x][y]) { Pos gp = Pos(x, y); if (0 == checkV(tg, gp)) { return false; } } else if (3 == board[x][y]) { Pos rp = Pos(x, y); if (0 == checkV(tg, rp) || 0 == checkH(tg, rp)) { return false; } } else if (4 == board[x][y]) { for (int ind = 0; ind < 8; ++ind) { int k = ind / 2; Pos hp, fp; hp.x = x + hDir[ind][0]; hp.y = y + hDir[ind][1]; fp.x = x + gDir[k][0]; fp.y = y + gDir[k][1]; if (inBoard(hp) && inBoard(fp)) { if (0 == board[fp.x][fp.y] && tg == hp) { return false; } } } } else if (5 == board[x][y]) { Pos cp = Pos(x, y); if (1 == checkV(tg, cp) || 1 == checkH(tg, cp)) { return false; } } } } return true;}bool judge(const Pos &bg){ Pos tg; board[bg.x][bg.y] = 0; for (int i = 0; i < 4; ++i) { tg.x = bg.x + gDir[i][0]; tg.y = bg.y + gDir[i][1]; if (inPalace(tg)) { int val = board[tg.x][tg.y]; board[tg.x][tg.y] = 1; if (canLive(tg)) { return false; } board[tg.x][tg.y] = val; } } return true;}void ace(){ int u, v; string str; bool sign; while (cin >> n >> u >> v, n || u || v) { CLR(board, 0); bg.x = u; bg.y = v; board[u][v] = 1; sign = false; for (int i = 0; i < n; ++i) { cin >> str >> u >> v; if ('G' == str[0]) { board[u][v] = 2; sign = true; wg.x = u; wg.y = v; } else if ('R' == str[0]) { board[u][v] = 3; } else if ('H' == str[0]) { board[u][v] = 4; } else if ('C' == str[0]) { board[u][v] = 5; } } if (sign) { if (0 == checkV(bg, wg)) { puts("NO"); continue ; } } puts( judge(bg) ? "YES" : "NO" ); } return ;}int main(){#ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin);#endif ace(); return 0;}

转载地址:http://zibqb.baihongyu.com/

你可能感兴趣的文章
为 Windows 98 的注册表数据库减肥(转)
查看>>
Windows Vista 内建管理员帐号被禁用(转)
查看>>
Geforce 4 MX 440强制Vista 开启玻璃效果(转)
查看>>
Windows Vista Beta2 中文版优化归类(转)
查看>>
用SQL进行多表查询(转)
查看>>
Oracle 9i管理工具的使用(转)
查看>>
目前主流的两类关系型数据库系统(转)
查看>>
在Oracle数据库10g中跟踪SQL(转)
查看>>
Oracle 10g Release2新功能之变化通知(转)
查看>>
Oracle 10g 新特性之虚拟专用数据库(转)
查看>>
深刻理解Oracle数据库的启动和关闭(转)
查看>>
将Oracle 10g内置的安全特性用于PHP(转)
查看>>
骇客攻击:跳板攻击与防御(1)(转)
查看>>
SYN Flood攻击的基本原理(转)
查看>>
用dhtml做了一个密码管理器 (转)
查看>>
Php 3.x与4.x中关于对象编程的不兼容问题 (转)
查看>>
Cg FAQ (转)
查看>>
在access中增加农历支持模块. (转)
查看>>
增加一个判断内存变量存在的函数 (转)
查看>>
JSR227:J2EE数据绑定及数据访问标准 (转)
查看>>