比赛 二进制状态表示之搜索中的应用 评测结果 AAAAAAAA
题目名称 城堡 最终得分 100
用户昵称 小金 运行时间 0.012 s
代码语言 C++ 内存使用 1.46 MiB
提交时间 2023-07-26 17:21:44
显示代码纯文本
#include<iostream>
#include<cstring>
using namespace std;
int q[55][55][10],b[55][55],n,m,t=0,qma=0,s=0,hma=0,xq,yq,qf;
void z0()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            b[i][j]=0;
        }
    }
}
void ch(int x,int y,int s)
{
    int t=1;
    while(s>0)
    {
        if(s&1==1)
        {
            q[x][y][t]=1;
        }
        t=t<<1;
        s=s>>1;
    }
}
void ff(int x,int y)
{
    if(b[x][y]==1)
    {
        return;
    }
    t++;
    b[x][y]=1;
    if(b[x][y-1]==0&&q[x][y][1]==0)
    {
        ff(x,y-1);
    }
    if(b[x-1][y]==0&&q[x][y][2]==0)
    {
        ff(x-1,y);
    }
    if(b[x][y+1]==0&&q[x][y][4]==0)
    {
        ff(x,y+1);
    }
    if(b[x+1][y]==0&&q[x][y][8]==0)
    {
        ff(x+1,y);
    }
    return;
}
int main()
{
    freopen("castle.in","r",stdin);
    freopen("castle.out","w",stdout);
    memset(q,0,sizeof(q));
    memset(b,0x3f,sizeof(b));
    cin>>m>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int a;
            cin>>a;
            ch(i,j,a);
        }
    }
    z0();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            ff(i,j);
            if(t>0)
            {
                s++;
                if(t>qma)
                {
                    qma=t;
                }
            }
            t=0;
        }
    }
    z0();
    for(int j=1;j<=m;j++)
    {
        for(int i=n;i>=1;i--)
        {
            if(q[i][j][2]==1)
            {
                q[i][j][2]=0;
                q[i-1][j][8]=0;
                ff(i,j);
                z0();
                if(t>hma)
                {
                    xq=i;
                    yq=j;
                    qf=2;
                    hma=t;
                }
                q[i][j][2]=1;
                q[i-1][j][8]=1;
                t=0;
            }
            if(q[i][j][4]==1)
            {
                q[i][j][4]=0;
                q[i][j+1][1]=0;
                ff(i,j);
                z0();
                if(t>hma)
                {
                    xq=i;
                    yq=j;
                    qf=4;
                    hma=t;
                }
                q[i][j][4]=1;
                q[i][j+1][1]=1;
                t=0;
            }
        }
    }
    cout<<s<<endl;
    cout<<qma<<endl;
    cout<<hma<<endl;
    cout<<xq<<' '<<yq<<' ';
    if(qf==2)
    {
        cout<<'N';
    }
    else
    {
        cout<<'E';
    }
    return 0;
}