Ancient Go(简单DFS)
题目链接: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 ;
}
Ancient Go(简单DFS)的更多相关文章
- Red and Black(简单dfs)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 1979 Red and Black (简单dfs)
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- POJ1979 Red and Black (简单DFS)
POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- hdu 4739 Zhuge Liang's Mines (简单dfs)
Zhuge Liang's Mines Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- CF760 C. Pavel and barbecue 简单DFS
LINK 题意:给出n个数,\(a_i\)代表下一步会移动到第\(a_i\)个位置,并继续进行操作,\(b_i\)1代表进行一次翻面操作,要求不管以哪个位置上开始,最后都能满足 1.到达过所有位置 2 ...
- uva 784 Maze Exploration(简单dfs)
这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar( ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- 题解报告:hdu 1312 Red and Black(简单dfs)
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
随机推荐
- mybatis-plus代码生成,实体类不生成父类属性
一.参考文档: 官方文档其实说的很清楚了,可能有个别地方有点不太清楚. mybatis-plus官方: https://mp.baomidou.com/guide/generator.html 模版引 ...
- .net 调用存储过程
语言:C# 一.调用带输入参数的存储过程 首先自然是在查询分析器里创建一个存储过程喽~~ 如下所示: create proc proc_1 @uid int, @pwd varchar(255) ...
- 2019年北航OO第4单元(UML)总结
1 架构设计 经过了接近一学期的程序设计训练,在这一单元的第一次作业中我就非常注重架构的设计,竭力避免像之前一样陷入"第一次作业凑合,第二次作业重构"的不健康的迭代模式.整体上来说 ...
- AppRTC服务搭建(测试)
提供一个在线的webrtc服务器测试,需要的朋友看看.https://www.webrtcserver.cn/ 服务器搭建环境各有不同在此参考前人经验差试一下. 运行AppRTC需要使用Google ...
- thinkphp5中使用phpmailer实现发送邮件功能
一.开启SMTP服务(使用php发送邮件需要用到SMTP服务,这里以163邮箱的SMTP服务为例). 1.登录163邮箱,在首页上找到“设置”. 2.选择开启的服务,一般都全选,POP3/SMTP/I ...
- 用weexplus从0到1写一个app(2)-页面跳转和文章列表及文章详情的编写
说明 结束连续几天的加班,最近的项目终于告一段落,今天抽点时间开始继续写我这篇拖了很久的<用weexplus从0到1写一个app>系列文章.写这篇文章的时候,weexplus的作者已经把w ...
- 大数据的前世今生【Hadoop、Spark】
一.大数据简介 大数据是一个很热门的话题,但它是什么时候开始兴起的呢? 大数据[big data]这个词最早在UNIX用户协会的会议上被使用,来自SGI公司的科学家在其文章“大数据与下一代基础架构 ...
- Centos7 docker安装GitLab
*先决条件系统已安装Docker 1.查询GitLab镜像 docker search gitlab 2.现在GitLab镜像 3.创建文件夹 mkdir -p /software/gitlab/co ...
- SpringBoot AOP概念及使用Demo
AOP核心概念1.横切关注点 对哪些方法进行拦截,拦截后怎么处理,这些关注点称之为横切关注点2.切面(aspect)->(通知+切点) 类是对物体特征的抽象,切面就是对横切关注点的抽象.通知+切 ...
- Flask之threading.loacl方法
一.threading.loacl方法 import threading import time class Foo: pass foo = Foo() def func(num): foo.num ...