温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

CDOJ 1221 Ancient Go

发布时间:2020-06-16 18:15:43 来源:网络 阅读:235 作者:邹君安 栏目:开发技术

CDOJ 1221 Ancient Go

#include<bits/stdc++.h>using namespace std;bool ok;char maze[15][15];char Map[12][12];bool vis[15][15];int x[4] = {0,0,1,-1};int y[4] = {1,-1,0,0};struct ST
{    int ii;    int jj;
};
queue<ST> que;void BFS(int cur_i, int cur_j)
{    int dot = 0;    while(!que.empty())
        que.pop();
    ST now;
    now.ii = cur_i;
    now.jj = cur_j;
    que.push(now);    while(!que.empty())
    {
        now = que.front();
        que.pop();
        vis[now.ii][now.jj] = 1;        for(int i=0;i<4;i++)
        {            int tempX = now.ii + x[i];            int tempY = now.jj + y[i];
            ST Next;
            Next.ii = tempX;
            Next.jj = tempY;            if(tempX >=0 && tempX <= 10 && tempY >=0 && tempY <= 10 && !vis[tempX][tempY])
            {                if(Map[tempX][tempY]=='.')
                {
                    dot++;
                    vis[tempX][tempY] = 1;
                }                else if(Map[tempX][tempY]=='o')
                {
                    que.push(Next);
                    vis[tempX][tempY] = 1;
                }
            }
        }
    }    if(dot == 1)
    {
        ok = 1;
    }    return ;
}int main()
{    int t;
    cin>>t;    int kase = 1;    while(t--)
    {
        ok = 0;        for(int i=0;i<=8;i++)
            cin>>maze[i];        for(int i=0;i<=10;i++)
        {            for(int j=0;j<=10;j++)
            {                if(i==0||j==0||i==10||j==10)
                    Map[i][j] = 'x';                else
                    Map[i][j] = maze[i-1][j-1];
            }
        }

        memset(vis, 0, sizeof(vis));        for(int i=1;i<=9;i++)
        {            for(int j=1;j<=9;j++)
            {                if(Map[i][j]=='o'&&!vis[i][j])
                    BFS(i, j);                for(int ii=1;ii<=9;ii++)                    for(int jj=1;jj<=9;jj++)                        if(Map[ii][jj] == '.')
                            vis[ii][jj] = 0;                if(ok)                    goto here;
            }
        }
        here:;        if(ok)
            printf("Case #%d: Can kill in one move!!!\n", kase++);        else
            printf("Case #%d: Can not kill in one move!!!\n", kase++);       // cout<<endl;
    }    return 0;
}

CDOJ 1221 Ancient Go


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI