点击打开链接

题意:给定一个9*9的棋盘,问黑子能否在下一步将白子围住(四面)。

由于数据不大,可以直接将'.'换成'x',用DFS搜索。

#include<cstdio>
#include<cstring>
using namespace std;
char chess[11][11];
bool visit[11][11];
int turnx[4]={1,-1,0,0};
int turny[4]={0,0,1,-1};
int flag;
bool in(int x,int y)
{
if(x<0||y<0||x>=9||y>=9)
return 0;
return 1;
}
void dfs(int x,int y)
{
if(chess[x][y]=='.')//如果有出路,则标记为0,说明在该点下子无法获胜
{
flag=0;
return;
}
for(int k=0;k<4;k++)
{
int nx=x+turnx[k];
int ny=y+turny[k];
if(in(nx,ny)&&!visit[nx][ny]&&chess[nx][ny]!='x')
{
visit[nx][ny]=1;
dfs(nx,ny);
}
}
}
int solve()
{
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
if(chess[i][j]=='.')
{
chess[i][j]='x';
for(int k=0;k<4;k++)
{
int nx=i+turnx[k];
int ny=j+turny[k];
if(in(nx,ny)&&chess[nx][ny]=='o')
{
memset(visit,0,sizeof(visit));
visit[nx][ny]=1;
flag=1;
dfs(nx,ny);
if(flag)
return 1;//直接返回,跳出循环
}
}
chess[i][j]='.';//还原
}
}
}
return 0;
}
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
for(int i=0;i<9;i++)
scanf("%s",chess[i]);
flag=1;
memset(visit,0,sizeof(visit));
int ans=solve();
if(ans)
printf("Case #%d: Can kill in one move!!!\n",cas++);
else
printf("Case #%d: Can not kill in one move!!!\n",cas++);
}
return 0;
}

HDU5546 Ancient Go DFS的更多相关文章

  1. K - Ancient Messages(dfs求联通块)

    K - Ancient Messages Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  2. 2015南阳CCPC G - Ancient Go dfs

    G - Ancient Go Description Yu Zhou likes to play Go with Su Lu. From the historical research, we fou ...

  3. HDU 3839 Ancient Messages(DFS)

    In order to understand early civilizations, archaeologists often study texts written in ancient lang ...

  4. hdu 3839 Ancient Messages (dfs )

    题目大意:给出一幅画,找出里面的象形文字. 要你翻译这幅画,把象形文字按字典序输出. 思路:象形文字有一些特点,分别有0个圈.1个圈.2个圈...5个圈.然后dfs或者bfs,就像油井问题一样,找出在 ...

  5. Ancient Go---hdu5546(dfs爆搜CCPC题目)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5546 题意就是两个人下围棋,问在下一颗x是否能杀死o,'.'是空位子: 枚举所有的点,判断是否合法即可 ...

  6. Ancient Go(简单DFS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5546 AC代码: #include<iostream> #include<cstdi ...

  7. Ancient Printer[HDU3460]

    Ancient Printer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Tot ...

  8. HDU1010 DFS+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

随机推荐

  1. Struts2动态结果(${})and全局结果(global-results)

    动态结果 例:根据判定动态结果区分用户进行登录 1.先在TestAction类中进行判定赋值 public class TestAction extends ActionSupport { priva ...

  2. Nginx+Php-fpm+MySQL+Redis源代码编译安装指南

    说明:本教程主要包括以下三个部分: 1. 源代码编译安装Nginx 2. 源代码编译安装php以及mysql.redis扩展模块 3. 配置虚拟主机 文中所涉及安装包程序均提供下载链接,欢迎使用 运行 ...

  3. HDU 4123(树的直径+单调队列)

    Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. Nginx 引入线程池,提升 9 倍性能

    转载:http://blog.csdn.net/wuliusir/article/details/50760357 众所周知,NGINX 采用异步.事件驱动的方式处理连接.意味着无需对每个请求创建专门 ...

  5. BZOJ2721 [Violet 5]樱花

    先令n! = a: 1 / x + 1 / y = 1 / a  =>  x = y * a / (y - a) 再令 k = y - a: 于是x = a + a ^ 2 / k  => ...

  6. oracle建库及plsql建表空间的用法

    所有程序—>ORACLE-JHEMR----------->配置和移植工具----->DataBase Configuration Assistant-------中间就需要改一个数 ...

  7. Threading.Tasks.Task多线程 静态全局变量(字典) --只为了记录

    --------------------------------------------------------------后台代码---------------------------------- ...

  8. Zabbix页面遇到历史记录的乱码需要修改数据库

    Zabbix页面遇到历史记录的乱码需要修改数据库: 解决办法: 1.将 zabbix 数据库中的表备份: 2.手动删除 zabbix 数据库: 3.重新创建 zabbix 库时手动指定字符集为 utf ...

  9. Deep Learning In NLP 神经网络与词向量

    0. 词向量是什么 自然语言理解的问题要转化为机器学习的问题,第一步肯定是要找一种方法把这些符号数学化. NLP 中最直观,也是到目前为止最常用的词表示方法是 One-hot Representati ...

  10. format 字符串

    http://www.cnblogs.com/mumble/archive/2011/05/25/2056462.html ShowMessage( Format('this is %.0f',[ t ...