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 ...
随机推荐
- bat批处理删除多少天前的文件
@echo off ::演示:删除指定路径下指定天数之前(以文件的最后修改日期为准)的文件. ::如果演示结果无误,把del前面的echo去掉,即可实现真正删除. ::本例需要Win2003/Vist ...
- Java对list进行分页,subList()方法实现分页
/** * 自定义List分页工具 * @author hanwl */ public class PageUtil { /** * 开始分页 * @param list * @param pageN ...
- docker 容器和镜像常用命令整理
- 进入恢复模式(Recovery HD)
进入恢复模式(Recovery HD) 1,选中要启动的虚拟机,随后点击VM菜单的启动按钮后面向下箭头,随后点击菜单项”打开电源时进入固件“. 2,在虚拟机里面,用上下键移动到”Enter setup ...
- 修改Excel脚本
批量修改Excel TODO: 批量修改Excel 功能: 将图片防止在本地,读取excel数据,拆分数据之后根本地照片名称对比,然后上传服务器,创建新得excel. #!/usr/bin/pytho ...
- SIM900 HTTP POST
AT+SAPBR=3,1,"CONTYPE","GPRS" OK AT+SAPBR=3,1,"APN","CMNET" ...
- python之变量的数据类型(3)dict 及解构简单介绍
一.变量的数据类型(3) 1. dict 字典dict 用{}来表示 键值对数据 {key:value} 唯一性 键 都必须是可哈希的 不可变的数据类型就可以当做字典中的键 值 没有任何限制 2.增删 ...
- angularcli 第三篇(数据循环*ngFor、条件判断*ngIf)
1.数据循环 *ngFor (1)普通循环 <ul> <li *ngFor = "let item of list" > {{ item }} </l ...
- MQTT协议及EMQ应用
MQTT是基于TCP/IP协议栈构建的异步通信消息协议,是一种轻量级的发布/订阅信息传输协议.MQTT在时间和空间上,将消息发送者与接受者分离,可以在不可靠的网络环境中进行扩展.适用于设备硬件存储空间 ...
- openstack虚拟机,采用ssh密钥登录
在openstack中,制作出的镜像有两种登录方式 1:直接密码登录 2:秘钥登录 在openstack中加入了公钥对应自己会有一份秘钥,该怎样用秘钥进行登录, 可以直接如图在控制节点中,输入ssh ...