溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CDOJ 1221 Ancient Go

發(fā)布時間:2020-06-16 18:15:43 來源:網(wǎng)絡(luò) 閱讀:241 作者:鄒君安 欄目:開發(fā)技術(shù)

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問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI