http://acm.hdu.edu.cn/showproblem.php?pid=5546

 

 

题意:现在Yu Zhou 和 Su Lu在下棋。Yu Zhou执黑子'x', Su Lu执白子'o'。下棋规则是这样的:若某一方能将另一方的(0<N)棋子全部围起来,则表示他吃了了这枚棋子。现在该Yu Zhou执黑子的走了,问他能不能在一步之内吃掉至少一枚白子。

 

分析:若白子周围有两个及其以上'.',那么黑子一定不能够吃掉白子。但需注意,几枚白子在一块的情况

 

 

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

#define INF 0x3f3f3f3f
const int maxn = 10;
typedef long long LL;
char maps[maxn][maxn];
int v[maxn][maxn];
int dir[4][2]={{0, 1},{1, 0},{0, -1},{-1, 0}};

int DFS(int x, int y)
{

       v[x][y]=1;
       int ans = 0;

       for(int i=0; i<4; i++)
       {
           int nx=dir[i][0]+x;
           int ny=dir[i][1]+y;

           if(nx>=0 && nx<9 && ny>=0 && ny<9 && !v[nx][ny])
           {
               if(maps[nx][ny]=='.')
               {
                   v[nx][ny] = 1;
                   ans ++;
               }
               else if(maps[nx][ny]=='o') ans += DFS(nx, ny);///判断若四周全部被白子包围的情况
           }
       }

     return ans;
}

int main()
{
    int T, cnt=1, ans, flag;

    scanf("%d", &T);

    while(T --)
    {
        flag = 0;

        for(int i=0; i<9; i++)
            scanf("%s", maps[i]);

        for(int i=0; i<9; i++)
        {
            for(int j=0; j<9; j++)
            {
                memset(v, 0, sizeof(v));

                if(maps[i][j]=='o')///若为白子,则对它进行DFS,判断它的周围有多少个'.',若小于2则它一定被围住
                {
                    ans=DFS(i, j);
                    if(ans<=1) flag = 1;
                }

                if(flag) break;
            }
            if(flag) break;
        }

        if(flag) printf("Case #%d: Can kill in one move!!!\n", cnt++);
        else printf("Case #%d: Can not kill in one move!!!\n", cnt++);
    }
    return 0;
}

/*
1
......ox.
.......o.
...o.....
..o.o....
.x.o.....
ooo......
ooo....o.
...x.....
........o
*/
View Code

 

posted on 2016-08-16 21:19  不忧尘世不忧心  阅读(154)  评论(0编辑  收藏  举报