hdu 4121 “將軍”狀態判斷

http://acm.hdu.edu.cn/showproblem.php?pid=4121

純模擬...

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
#define clr1(x) memset(x,-1,sizeof(x))
#define eps 1e-9
const double pi = acos(-1.0);
typedef long long LL;
const int inf = 1000000000;
const int maxn = 15;
typedef pair<int,int> p2;
int dx[] = {1,-1,0,0},
    dy[] = {0,0,1,-1};
int hx[] = {1,2,-1,-2,1,2,-1,-2},
    hy[] = {2,1,2,1,-2,-1,-2,-1};
int lx[] = {1,1,-1,-1,1,1,-1,-1},
    ly[] = {1,1,1,1,-1,-1,-1,-1};
char p[maxn][maxn];
bool in(int x,int y)
{
    return 1 <= x && 10 >= x && 1 <= y && 9 >= y;
}
bool check(int x,int y)
{
    int fx = x,fy = y;
    for(int i = 0;i < 4;++i){
        fx = x + dx[i],fy = y + dy[i];
        int cnt = 0;
        while(in(fx,fy)){
            if(cnt == 0 && (p[fx][fy] == 'G' || p[fx][fy] == 'R'))
                return true;
            else if(cnt == 1 && (p[fx][fy] == 'C'))
                return true;
            else if(p[fx][fy] != 0)
                cnt++;
            fx += dx[i];
            fy += dy[i];
        }
    }
    for(int i = 0;i < 8;++i){
        int tx = x + hx[i],ty = y + hy[i];
        int lgx = x + lx[i],lgy = y + ly[i];
        if(p[tx][ty] == 'H' && p[lgx][lgy] == 0)
            return true;
    }
    return false;
}
int main()
{
    int n,bx,by,x,y;
    char typ[2];
    while(~RD3(n,bx,by) && (n|bx|by)){
        clr0(p);
        for(int i = 0;i < n;++i){
            scanf("%s",typ);
            RD2(x,y);
            p[x][y] = typ[0];
        }
        bool flag = true;
        for(int i = 0;i < 4;++i){
            int tx = bx + dx[i],ty = by + dy[i];
            if(in(tx,ty) && abs(tx-2) <= 1 && abs(ty-5) <= 1){
                if(!check(tx,ty)){
                    //printf("%d %d\n",tx,ty);
                    flag = false;
                    break;
                }
            }
        }
        printf("%s\n",flag?"YES":"NO");
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章