HDU 4121----------求助,幫我看看那種情況沒考慮到啊? -开发者知识库

HDU 4121----------求助,幫我看看那種情況沒考慮到啊? -开发者知识库,第1张

#include<iostream> 

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include <algorithm>
#define N 100007
#define inf 0x7f7f7f7f
using namespace std;
char c[8];
int a[8][2];
int r,l;
int flag;
int dx[4]= {-1,0,1,0};
int dy[4]= {0,1,0,-1};
int hx[4][2]= {-2,-2,-1,1,2,2,1,-1};
int hy[4][2]= {-1,1,2,2,1,-1,-2,-2};
bool m[15][15];

int ggg(int x,int y,int xx,int yy)
{
    if(y==yy)
    {
        if(x>xx)
            swap(x,xx);
        int flag=1;
        for(int i=x 1; i<xx; i )
            if(m[i][y]==1)
            {
                flag=0;
                break;
            }
        if(flag)
            return 1;
    }
    return 0;
}
int rrr(int x,int y,int xx,int yy)
{
    if(x==xx&&y==yy)
        return 0;//NO
    if(y==yy)
    {
        if(x>xx)
            swap(x,xx);
        int flag=1;
        for(int i=x 1; i<xx; i )
            if(m[i][y]==1)
            {
                flag=0;
                break;
            }
        if(flag)
            return 1;
    }
    if(x==xx)
    {
        if(y>yy)
            swap(y,yy);
        int flag=1;
        for(int i=y 1; i<yy; i )
            if(m[x][i]==1)///////////////
            {
                flag=0;
                break;
            }
        if(flag)
            return 1;
    }
    return 0;
}
int ccc(int x,int y,int xx,int yy)
{
//        cout<<x<<"   "<<y<<endl;
//        cout<<"========="<<endl;
    if(x==xx&&y==yy)
        return 0;//NO
    if(y==yy)
    {
        if(x>xx)
            swap(x,xx);
        int count=0;
        for(int i=x 1; i<xx; i )
            if(m[i][y]==1)
            {
                count ;
            }
        if(count==1)
            return 1;
    }
    if(x==xx)
    {
        if(y>yy)
            swap(y,yy);
        int count=0;
        for(int i=y 1; i<yy; i )
            if(m[x][i]==1)
            {
                count ;
            }
        if(count==1)
            return 1;
    }
    return 0;
}


int hhh(int jx,int jy,int x,int y)//x   jiang
{
    if(x==jx||y==jy)
        return 0;//NO
    for(int i=0; i<4; i )
    {
        if(!m[x dx[i]][y dy[i]])
        {
            if(x hx[i][0]==jx&&y hy[i][0]==jy)
                return 1;
            if(x hx[i][1]==jx&&y hy[i][1]==jy)
                return 1;
        }

    }
    return 0;






//    if(m[xx 1][yy]!=1)
//    {
//        if(x-xx==2&&(y-yy==1||y-yy==-1))
//            return 1;
//    }
//    if(m[xx-1][yy]!=1)
//    {
//        if(x-xx==-2&&(y-yy==1||y-yy==-1))
//            return 1;
//    }
//    if(m[xx][yy 1]!=1)
//    {
//        if(y-yy==2&&(x-xx==1||x-xx==-1))
//            return 1;
//    }
//    if(m[xx][yy-1]!=1)
//    {
//        if(y-yy==-2&&(x-xx==1||x-xx==-1))
//            return 1;
//    }

    return 0;
}
int main()
{
    freopen("ex.in","r",stdin);
    int n;
    while(scanf("%d%d%d%*c",&n,&r,&l)&&(n!=0||r!=0||l!=0))
    {
        memset(m,0,sizeof(m));

        flag=0;
        int f=-1;
        for (int i=0; i<n ; i  )
        {
            scanf("%c%d%d%*c",&c[i],&a[i][0],&a[i][1]);
            m[a[i][0]][a[i][1]]=1;
            if(c[i]=='G')
                f=i;
        }






        int flag2=1;
        if(f!=-1)
        {
            if(a[f][1]==l)
            {
                for(int i=r 1; i<a[f][0]; i )
                    if(m[i][l])
                    {
                        flag2=0;
                        break;
                    }
                if(flag2)
                {
                    printf("NO\n");
                    continue;
                }
            }
        }


        int x,y;
        int ans=0;
        for (int i=0; i<4 ; i  )
        {
//            cout<<"i="<<i<<endl;
            x=r dx[i];
            y=l dy[i];
            if(y<4||y>6||x<1||x>3)
                continue;

            ans = 1;//ans=0;//
            for (int j=0; j<n ; j  ) //
                if(c[j]=='G')
                {
                    ans=ggg(x,y,a[j][0],a[j][1]);
                    if(ans)
                    {
//                        cout<<"ggggggggggg"<<endl;
                        break;
                    }
                }
                else if(c[j]=='R')
                {
                    ans=rrr(x,y,a[j][0],a[j][1]);
                    if(ans)
                    {
//                        cout<<x<<"   "<<y<<endl;
//                        cout<<"rrrrrrrr"<<endl;
                        break;
                    }

                }
                else if(c[j]=='H')
                {
                    ans=hhh(x,y,a[j][0],a[j][1]);
                    if(ans)
                    {
//                        cout<<"hhhhhhhh"<<endl;
                        break;
                    }
                }
                else if(c[j]=='C')
                {
                    ans=ccc(x,y,a[j][0],a[j][1]);
                    if(ans)
                    {
//                        cout<<"cccccccc"<<endl;
                        break;
                    }
                }
            if(!ans)
            {
                break;
            }

        }
        if(!ans)
            printf("NO\n");
        else
            printf("YES\n");
//        char d;
//        cin>>d;
//        cout<<"d="<<d<<endl;
    }

    return 0;
}
 








幫我看看那種情況沒考慮到啊?

3 个解决方案

#1


好復雜!
情況沒考慮到

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复