小火山的围棋梦想

题目链接:点击打开链接

代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace   std;
#include<queue>
int x[5]= {0,0,1,-1};
int y[5]= {1,-1,0,0};
char  q[30][30];
int  w1[30][30];
struct  qq
{
    int i1,j1;
} ;
int panduan(int i,int j)
{
    int flag=0;
    qq a;
    a.i1=i;
    a.j1=j;
    queue<qq>w;
    while(!w.empty())
    {
        w.pop();
    }
    w.push(a);
    w1[i][j]=1;
    while(!w.empty())
    {
        qq a1=w.front();
        w.pop();
//        w1[a1.i1][a1.j1]=0;
        for(int t=0; t<4; t++)
        {
            qq a2;
            a2.i1=a1.i1+x[t];
            a2.j1=a1.j1+y[t];
            if(q[a1.i1+x[t]][a1.j1+y[t]]=='0')
            {
                flag=1;
                break;
            }

            else  if(q[a1.i1+x[t]][a1.j1+y[t]]=='*')
                continue;
            else  if(q[a1.i1+x[t]][a1.j1+y[t]]=='.')
                if(w1[a2.i1][a2.j1]==0)
                {
                    w.push(a2);
                    w1[a2.i1][a2.j1]=1;

                }


        }

        if(flag==1)
            while(!w.empty())
            {
                w.pop();
            }
    }
    return flag;
}
int main()
{
    int a;
    scanf("%d",&a);
    getchar();
    int r=1;
    while(a--)
    {
        int q1,q2;
        scanf("%d %d",&q1,&q2);
        getchar();
        memset(q,'0',sizeof(q));

        for(int i=1; i<=q1; i++)
        {
            for(int j=1; j<=q2; j++)
                q[i][j]=getchar();
            getchar();
        }
        for(int i=1; i<=q1; i++)
            for(int j=1; j<=q2; j++)
                if(q[i][j]=='.')
                {
                    memset(w1,0,sizeof(w1));
                    if(!panduan(i,j))
                        q[i][j]='*';
                }
        printf("Case %d:\n",r);
        r++;
        for(int i=1; i<=q1; i++)
        {
            for(int j=1; j<=q2; j++)
                printf("%c",q[i][j]);
            printf("\n");
        }

//        printf("%d\n",q[0][0]=='0');
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值