Ancient Go(简单DFS)
2024-08-22 13:53:25
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5546
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
const double pi = acos(-1.0);
const ll mod = 1e9 + ;
const int inf = 0x3f3f3f3f;
const int maxn = 5e4 + ;
int Next[][] = {{, }, {, }, {-, }, {, -}};
char str[][];
int vis[][];
bool check1(int x, int y)
{
vis[x][y] = ;
for(int i=;i<;i++)
{
int xx = x + Next[i][];
int yy = y + Next[i][];
if(xx >= && xx < && yy >= && yy < && !vis[xx][yy])
{
/* 两种情况表示在已经换了一个的情况下,还没有封死*/
if(str[xx][yy] == '.') return true;
if(str[xx][yy] == 'o' && check1(xx, yy)) return true;
}
}
return false;
}
bool check(int x, int y)
{
str[x][y] = 'x';///把点换为‘x'
bool flag= false;
for(int i=;i<;i++)
{
int xx = x + Next[i][];
int yy = y + Next[i][];
if(xx >= && xx < && yy >= && yy < )
{
if(str[xx][yy] == 'o')
{
memset(vis, , sizeof(vis));
if(!check1(xx, yy))///检查此'o'是否被封死
{
flag = true;
break;
}
}
}
}
str[x][y] = '.';///取消改换
return flag;
}
int main()
{
int t;
cin >> t;
int k = ;
while(t--)
{
for(int i=;i<;i++)
{
cin >> str[i];
}
bool flag = false;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(str[i][j] == 'x' || str[i][j] == 'o') continue;
else
{
if(check(i, j))///检查是否有o的周围再加一个x可以被封死
{
flag = true;
break;
}
}
}
if(flag) break;
}
cout << "Case #" << k++ << ": ";
if(flag) cout << "Can kill in one move!!!" << endl;
else cout << "Can not kill in one move!!!" << endl;
}
return ;
}
最新文章
- opensuse sublime 配置
- WebApi Put方法出现MethodNotAllowed解决方法
- 1.1 让CPU占用率曲线听你指挥[cpu manager]
- Python使用MySQL数据库的方法以及一个实例
- CSS - 实现文字显示过长时用省略
- C++中的重载、覆盖、隐藏
- 10个工具让你的 shell 脚本更强大
- mysql中datetime和timestamp的区别
- ucos队列的实现--源码分析
- python 鸭子类型
- node中间层实现文件上传
- cpuset
- Android 错误提示: Can&#39;t create handler inside thread that has not called Looper.prepare()
- 很清晰的解读i2c协议【转】
- mysql中关于关联索引的问题——对a,b,c三个字段建立联合索引,那么查询时使用其中的2个作为查询条件,是否还会走索引?
- beta冲刺————第三天(3/5)
- listview点击控件显示EditText,键盘弹出消失的解决方法:
- localforage 对不同浏览器 使用不同的缓存策略 , 大大提高了性能 ,IndexedDB,WebSQL 和 localStorage 三种存储模式
- js实现loading简单的遮套层
- 理解Linux内核之中断控制