hdu 5546 Ancient Go(★)
2016-03-12 20:11
387 查看
题意: 有两个人在一个9*9的棋盘里下棋,A 是的棋子为x , B为 o ,“.” 的意思为空。 问 A的下一个 能否将 B 的棋子杀死, (跟围棋差不多)。
解题大意: dfs 判联通块的周围是否只有 一个 ‘ . ’.
解题大意: dfs 判联通块的周围是否只有 一个 ‘ . ’.
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; char ma[10][10]; int vis[10][10],num,cnt; int mx[4] = {0,0,1,-1}; int my[4] = {1,-1,0,0}; void dfs(int x,int y) { //printf("%d %d\n",x,y); vis[x][y] = cnt; for(int i = 0; i < 4; i++) { int rx = x + mx[i]; int ry = y + my[i]; if(rx < 0 || rx > 8 || ry < 0 || ry > 8) continue; if(ma[rx][ry] == 'x') continue; if(vis[rx][ry] == cnt) <span style="color:#ff0000;">//标记vis数组要用cnt,不能用1,因为要考虑多个白棋周围相同的空白点</span> continue; if(ma[rx][ry] == '.') { num++; vis[rx][ry] = cnt; } if(ma[rx][ry] == 'o') dfs(rx,ry); } } int main() { int n,m,t,C = 1; scanf("%d",&t); while(t--) { for(int i = 0; i < 9; i++) scanf("%s",ma[i]); int flag = 0; cnt = 0; memset(vis,0,sizeof(vis)); for(int i = 0; i < 9; i++) for(int j = 0; j < 9; j++) { if(ma[i][j] == 'o' && !vis[i][j]) { vis[i][j] = 1; num = 0; cnt++; dfs(i,j); if(num == 1) { flag = 1; //printf("%d %d\n",i,j); } } } if(flag) printf("Case #%d: Can kill in one move!!!\n",C++); else printf("Case #%d: Can not kill in one move!!!\n",C++); } }
相关文章推荐
- 读书笔记:Mastering the game of Go with deep neural networks and tree search
- 蓝桥杯 algo——6 安慰奶牛 (最小生成树)
- AlphaGo三比零完胜李世石
- AlphaGo三比零完胜李世石
- 蓝桥杯 algo_5 最短路 (bellman,SPFA)
- hdu Dragon Balls 3635【并查集】
- Category添加属性字段
- 蓝桥杯 ALGO-4 结点选择 (树形动态规划)
- BZOJ 2097 USACO 2010 Dec Gold Exercise 奶牛健美操 二分答案 树形DP 贪心
- Goldengate 使用definition file完成异构表同步
- mongoose中如何给数据添加对应schema中没有的字段
- WebGIS中基于AGS的画圆查询简析以及通过Polygon来构造圆的算法
- Django使用第三方接口(一)
- Understanding Google Analytics Diagnostic messages and notifications
- 基于Google Code Prettify wordpress插件WP-code-button
- POJ 2195 Going Home 最小费用最大流 尼玛,心累
- Goldengate 简单部署测试
- 关于 AlphaGo 论文的阅读笔记
- django url.py name字段
- Google翻译