现在的位置: 首页 > 综合 > 正文

【模拟】2011 Asia Fuzhou Regional Contest hdu 4121

2013年08月28日 ⁄ 综合 ⁄ 共 2374字 ⁄ 字号 评论关闭

看清楚题目,帅只能走四个方向,枚举四个方向,然后先判马,再判四个方向的直线(其中若直线最近的是马或炮,判后面那个是否是炮)

#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <time.h>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <cstdlib>
#include <limits.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

#define LL long long
#define MIN INT_MIN
#define MAX INT_MAX
#define pii pair<int ,int>
#define mp make_pair
#define PI acos(-1.0)
#define FRE freopen("input.txt","r",stdin)
#define FF freopen("output.txt","w",stdout)
#define N 22

//G R H C
char g[13][13];
int d[4][2] = {0,1,0,-1,-1,0,1,0};
int dd[8][2] = {1,-2,-1,-2,-2,-1,-2,1,-1,2,1,2,2,1,2,-1};
vector<char> v;
bool ma(int x,int y) {
    int i,j;
    if((g[x-1][y-2] == 'H' && x-1 >= 1) || (g[x-2][y-1] == 'H' && x - 2 >= 1)) 
    {
        if(g[x-1][y-1] == '\0')
            return  false;
    }
    if(g[x+1][y-2] == 'H'  || g[x+2][y-1] == 'H')
    {
        if(g[x+1][y-1] == '\0')
            return  false;
    }
    if((g[x-2][y+1] == 'H' && x-2 >= 1)|| (g[x-1][y+2] == 'H' && x-1 >= 1) )
    {
        if(g[x-1][y+1] == '\0')
            return  false;
    }
    if(g[x+2][y+1] == 'H' || g[x+1][y+2] == 'H')
    {
        if(g[x+1][y+1] == '\0')
            return  false;
    }
    return true;//ok
}

bool chk(int x,int y) {
    int i,j;
    int sz = 0;
    v.clear();
    for (j = y-1; j >= 1; j--) {
        if (g[x][j] != '\0') {
            v.push_back(g[x][j]);
        }
    }
    sz = v.size();
    if (sz) {
        if (v[0] == 'H' || v[0] == 'C') {
            if (sz > 1 && v[1] == 'C') {
                return false;
            }
        } else if (v[0] == 'G') return false;
          else if (v[0] == 'R') return false;
    }
    ////////////////////////////////
    v.clear();
    for (i = x-1; i >= 1; i--) {
        if (g[i][y] != '\0') {
            v.push_back(g[i][y]);
        }
    }
    sz = v.size();
    if (sz) {
        if (v[0] == 'H' || v[0] == 'C') {
            if (sz > 1 && v[1] == 'C') {
                return false;
            }
        } else if (v[0] == 'G') return false;
          else if (v[0] == 'R') return false;
    }
    ////////////////////////////////
    v.clear();
    for (j = y+1; j <= 9; j++) {
        if (g[x][j] != '\0') {
            v.push_back(g[x][j]);
        }
    }
    sz = v.size();
    if (sz) {
        if (v[0] == 'H' || v[0] == 'C') {
            if (sz > 1 && v[1] == 'C') {
                return false;
            }
        } else if (v[0] == 'G') return false;
          else if (v[0] == 'R') return false;
    }
    /////////////////////////////////////
    v.clear();
    for (i = x+1; i <= 10; i++) {
        if (g[i][y] != '\0') {
            v.push_back(g[i][y]);
        }
    }
    sz = v.size();
    if (sz) {
        if (v[0] == 'H' || v[0] == 'C') {
            if (sz > 1 && v[1] == 'C') {
                return false;
            }
        } else if (v[0] == 'G') return false;
          else if (v[0] == 'R') return false;
    }
    ///////////////////////////////
    return true;
}

int main(){
    int n,x,y;
    while (cin>>n>>x>>y && n,x,y) {
        int i,j;
        memset(g,'\0',sizeof(g));
        while (n--) {
            char c;
            int xx,yy;
            cin>>c>>xx>>yy;
            g[xx][yy] = c;
        }
        bool ok = 0;
        for (i = 0; i < 4; i++) {
            int xx = x, yy = y;
            xx += d[i][0];
            yy += d[i][1];
            if (xx >= 1 && xx <= 3 && yy >= 4 && yy <= 6) {
                if (ma(xx,yy) && chk(xx,yy)) {
                    ok = 1;//可走
                    break;
                }
            }
        }
        if (ok) {
            printf("NO\n");//不将死
        } else {
            printf("YES\n");
        }
    }
    return 0;
}

抱歉!评论已关闭.