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 ...
随机推荐
- 机器学习 降维算法: isomap & MDS
最近在看论文的时候看到论文中使用isomap算法把3D的人脸project到一个2D的image上.提到降维,我的第一反应就是PCA,然而PCA是典型的线性降维,无法较好的对非线性结构降维.ISOMA ...
- JAVA MyBybatis分页
java: import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; impo ...
- cefsharp System.IO.FileNotFoundException: 未能加载文件或程序集“CefSharp.Core.dll”或它的某一个依赖项。
解决办法 安装vc++ 2015 Redistributable 64位系统安装x64 如果还报错先装x64版本再装x86版本 https://files.cnblogs.com/files/xuej ...
- Java High Level REST Client 使用示例
概述 ES 在 7.0 版本开始将废弃 TransportClient,8.0 版本开始将完全移除 TransportClient,取而代之的是 High Level REST Client,官方文档 ...
- Ceph集群部署(基于Luminous版)
环境 两个节点:ceph0.ceph1 ceph0: mon.a.mds.mgr.osd.0.osd.1 ceph1: mon.b.osd.2.osd.3 操作系统:ubuntu14.04 网络配置: ...
- django后台xadmin如下配置(小结)
django-admin文档:https://xadmin.readthedocs.io/en/latest/index.html目录: 1.xadmin基本配置 2.配置后台显示的模型类 3.后台注 ...
- Springboot手动获取bean
使用如下工具类即可 package com.rio.ums.spa.commons.utils; import org.springframework.beans.BeansException; im ...
- TODO : 一些新的学习计划
1.读完jvm那本书 2.加深Android的开发知识 3.编写atx的demo 4.跑几个apk的性能测试并做详细的性能分析 5.尝试实现一个uiautomator多个手机同时执行脚本的可能性(连线 ...
- Keras神经网络data generators解决数据内存
在使用kears训练model的时候,一般会将所有的训练数据加载到内存中,然后喂给网络,但当内存有限,且数据量过大时,此方法则不再可用.此博客,将介绍如何在多核(多线程)上实时的生成数据,并立即的送入 ...
- LG4762 Virus synthesis
Virus synthesis 初始有一个空串,利用下面的操作构造给定串 S . 串开头或末尾加一个字符 串开头或末尾加一个该串的逆串 求最小化操作数, ∣S∣≤105 . 题解 显然应该多使用操作2 ...