hdu4121 Xiangqi(模拟)

模拟题一般要考虑情况的!

将走一步可能走出范围或者吃掉红方的一个棋子;将帅直线且中间无子的时候,帅可以直接冲将;卡马脚的时候,马不能往跳那个方向跳。

//#pragma comment(linker, "/STACK:102400000")
#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#define tree int o,int l,int r
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define lo o<<1
#define ro o<<1|1
#define pb push_back
#define mp make_pair
#define ULL unsigned long long
#define LL long long
#define inf 0x7fffffff
#define eps 1e-7
#define N 20
using namespace std;
int m,n,T,t,x,y;
int ma[20][20],a[N][N];
char str[N];
struct Node
{
    char c;
    int x,y;
} node[N];
int dx[4]= {-1,0,1,0};
int dy[4]= {0,1,0,-1};
int xwu(int x1,int x2,int y1)
{
    for(int i=min(x1,x2)+1; i<max(x1,x2); i++)
        if(ma[i][y1]!=0)return 0;
    return 1;
}
int ywu(int y1,int y2,int x)
{
    for(int i=min(y1,y2)+1; i<max(y1,y2); i++)
        if(ma[x][i]!=0)return 0;
    return 1;
}
int xnum(int x1,int x2,int y1)
{
    int ans=0;
    for(int i=min(x1,x2)+1; i<max(x1,x2); i++)
        if(ma[i][y1]!=0)ans++;
    return ans;
}
int ynum(int y1,int y2,int x)
{
    int ans=0;
    for(int i=min(y1,y2)+1; i<max(y1,y2); i++)
        if(ma[x][i]!=0)ans++;
    return ans;
}
int eat(int x1,int y1,Node &p)
{
    int x2=p.x,y2=p.y;
    if(p.c=='G')
    {
        if(y2==y1&&xwu(x1,x2,y1))
        {
            return 1;
        }
        return 0;
    }
    if(p.c=='R')
    {
        if(y2==y1&&xwu(x1,x2,y1))
        {
            return 1;
        }
        if(x1==x2&&ywu(y1,y2,x1))
        return 1;
        return 0;
    }
    if(p.c=='C')
    {
        if(y2==y1&&xnum(x1,x2,y1)==1)
        {
            return 1;
        }
        if(x1==x2&&ynum(y1,y2,x1)==1)
        return 1;
        return 0;
    }
    if(p.c=='H')
    {
        int all=abs(x1-x2)+abs(y1-y2);
        int cx=abs(x1-x2);
        if(all==3&&(cx==1||cx==2))
        {
            int xx=x2,yy=y2;
            if(cx==2)
            {
                xx+=(x1-x2)/2;
            }
            else
            {
                yy+=(y1-y2)/2;
            }
            if(ma[xx][yy]==0)return 1;
        }
        return 0;
    }

}
int ok(int x,int y)
{
    for(int i=0; i<n; i++)
        if(node[i].x!=x||node[i].y!=y)
        {
            if(eat(x,y,node[i]))return 0;
        }
    return 1;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("ex.in","r",stdin);
#endif
    while(scanf("%d%d%d%*c",&n,&x,&y)==3)
    {
        if(!n&&!x&&!y)return 0;
        memset(a,0,sizeof(a));

        for (int i=0; i<n; ++i )
        {
            scanf("%s%d%d",str,&node[i].x,&node[i].y);
            node[i].c=str[0];
            a[node[i].x][node[i].y]=1;
        }
        int ans=0;
        for(int i=0; i<4; i++)
        {
            int xx=x+dx[i];
            int yy=y+dy[i];
            memcpy(ma,a,sizeof(a));
            ma[xx][yy]=0;
            if(xx>=1&&xx<=3&&yy>=4&&yy<=6)
            {
                if(ok(xx,yy))
                {
                    ans=1;
                    break;//chibudiao
                }
            }
        }
        puts(ans==1?"NO":"YES");
    }
    return 0;
}

posted @ 2013-10-20 21:33  baoff  阅读(157)  评论(0编辑  收藏  举报