CDOJ 1221 Ancient Go

时间:2022-11-26 20:05:36

题目链接http://acm.uestc.edu.cn/#/problem/show/1221

题目分类:dfs

代码

#include<bits/stdc++.h>

using namespace std;

bool ok;
char maze[][];
char Map[][];
bool vis[][];
int x[] = {,,,-};
int y[] = {,-,,}; struct ST
{
int ii;
int jj;
};
queue<ST> que; void BFS(int cur_i, int cur_j)
{
int dot = ;
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] = ;
for(int i=;i<;i++)
{
int tempX = now.ii + x[i];
int tempY = now.jj + y[i];
ST Next;
Next.ii = tempX;
Next.jj = tempY;
if(tempX >= && tempX <= && tempY >= && tempY <= && !vis[tempX][tempY])
{
if(Map[tempX][tempY]=='.')
{
dot++;
vis[tempX][tempY] = ;
}
else if(Map[tempX][tempY]=='o')
{
que.push(Next);
vis[tempX][tempY] = ;
}
}
}
}
if(dot == )
{
ok = ;
}
return ;
} int main()
{
int t;
cin>>t;
int kase = ;
while(t--)
{
ok = ;
for(int i=;i<=;i++)
cin>>maze[i];
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(i==||j==||i==||j==)
Map[i][j] = 'x';
else
Map[i][j] = maze[i-][j-];
}
} memset(vis, , sizeof(vis));
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
if(Map[i][j]=='o'&&!vis[i][j])
BFS(i, j);
for(int ii=;ii<=;ii++)
for(int jj=;jj<=;jj++)
if(Map[ii][jj] == '.')
vis[ii][jj] = ;
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 ;
}