zoukankan      html  css  js  c++  java
  • 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!!!
    ", kase++);
            else
                printf("Case #%d: Can not kill in one move!!!
    ", kase++);
           // cout<<endl;
        }
        return 0;
    }
    复制代码
  • 相关阅读:
    实时日历
    添加与删除
    php 变量 循环关键词以及方法
    php中各种操作字符串和时间戳的代码关键词
    php中数组相关
    php中普通方法和静态方法的区别以及抽象类和接口
    php设计模式 工厂模式和单例
    面对对象7大原则整理
    PHP中include与require的特点和区别说明
    php基础运算符语句
  • 原文地址:https://www.cnblogs.com/zhaodahai/p/6825331.html
Copyright © 2011-2022 走看看