模拟题
黑方只有一个将,决定是否被死将,规则和普通象棋一致
注意细节就没什么难的
我是先判断能否飞将。然后判断走四个方向后会不会被将死
这里需要注意一点,移动后可能会吃掉红方一颗棋子,那么这颗棋子就不需要判断
//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")
//HEAD
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
//STL
#define SZ(V) (int)V.size()
#define PB push_back
#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)
#define ALL(c) (c).begin(), (c).end()
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RS(s) scanf("%s", s)
//OUTPUT
#define WI(n) printf("%d\n", n)
#define WS(s) printf("%s\n", s)
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const int INF = 100000000;
const double eps = 1e-10;
const int maxn = 210;
const LL MOD = 1e9 + 7;
const int g = 0, r = 1, h = 2, c = 3;
int N, nx, ny;
int dirh[][2] = {{-2, -1}, {-2, 1}, {-1, 2}, {1, 2},
{2, 1}, {2, -1}, {1, -2}, {-1, -2} };
int dirg[][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
struct node{
int x, y, ty;
}gen, genr, piece[10];
bool vis[12][12];
bool fly()
{
if (gen.y != genr.y)
return 0;
bool f = 1;
FE(i, gen.x + 1, genr.x - 1)
if (vis[i][gen.y])
return 0;
return 1;
}
bool check(int x, int y, int ty) /// is eaten return 0
{
if (ty == 0)
{
if (y == ny)
{
FE(i, nx + 1, x - 1)
if (vis[i][y])
return 1;
return 0;
}
return 1;
}
else if (ty == 1)
{
bool f = 1;
if (x == nx)
{
FE(i, min(y, ny) + 1, max(y, ny) - 1)
if (vis[x][i])
return 1;
return 0;
}
else if (y == ny)
{
FE(i, min(x, nx) + 1, max(x, nx) - 1)
if (vis[i][y])
return 1;
return 0;
}
else
return 1;
}
else if (ty == 2)
{
REP(i, 8)
{
int xx = x + dirh[i][0], yy = y + dirh[i][1];
int biex = x + dirg[i / 2][0], biey = y + dirg[i / 2][1];
if (!vis[biex][biey] && xx == nx && yy == ny)
return 0;
}
return 1;
}
else
{
int cnt = 0;
if (nx == x)
{
FE(i, min(y, ny) + 1, max(y, ny) - 1)
if (vis[x][i])
cnt++;
if (cnt == 1)
return 0;
return 1;
}
else if (ny == y)
{
FE(i, min(x, nx) + 1, max(x, nx) - 1)
if (vis[i][y])
cnt++;
if (cnt == 1)
return 0;
return 1;
}
else
return 1;
}
return 0;
}
bool solve()
{
if (genr.y != -1 && fly())
return 1;
bool f = 1;
REP(i, 4)
{
f = 1;
nx = gen.x + dirg[i][0], ny = gen.y + dirg[i][1];
if (nx <=3 && nx >= 1 && ny <= 6 && ny >= 4)
{
// printf("General: %d %d\n", nx, ny);
REP(i, N)
{
if (piece[i].x == nx && piece[i].y == ny)///这颗棋子被吃
continue;
if (!check(piece[i].x, piece[i].y, piece[i].ty))
{
// printf("Eaten by %d\n", piece[i].ty);
f = 0;
break;
}
}
if (f) return 1;
}
}
return 0;
}
int main()
{
char type[10];
while (RIII(N, gen.x, gen.y) && (N || gen.x || gen.y))
{
gen.ty = 0, genr.x = -1, genr.y = -1;
CLR(vis, 0);
REP(i, N)
{
RS(type);
if (type[0] == 'G')
piece[i].ty = 0;
else if (type[0] == 'R')
piece[i].ty = 1;
else if (type[0] == 'H')
piece[i].ty = 2;
else
piece[i].ty = 3;
RII(piece[i].x, piece[i].y);
if (piece[i].ty == 0)
genr.x = piece[i].x, genr.y = piece[i].y;
vis[piece[i].x][piece[i].y] = 1;
}
printf(solve()? "NO\n":"YES\n");
}
}