/****************************************************************************************************
坑爹的模拟题~注意这两种情况:黑方的将能直接飞过去杀了红方的将,还有将走一步能把红方别的子给吃了。。。
****************************************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
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<t>(s)
#define LEN(s) static_cast<int>( strlen((s)) )
#define SZ(s) static_cast<int>( (s).size() )
typedef double LF;
//typedef long long LL; //GNU C++
//typedef unsigned long long ULL;
typedef __int64 LL; //Visual C++ 2010
typedef unsigned __int64 ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<int>::iterator LI;
typedef set<int>::iterator SI;
template <typename T>
T sqa(const T &x)
{
return x * x;
}
template <typename T>
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 <typename T>
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 <typename T>
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; //15f
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);
#define ONLINE_JUDGE
const 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;
}
HDU 4121 模拟
最新推荐文章于 2020-02-16 10:57:32 发布