HDU 5546 Ancient Go
2015-11-27 13:00
447 查看
数据范围小,可以写得很暴力
枚举下棋的位置,然后再检查,可以dfs,可以bfs,还可以并查集
枚举下棋的位置,然后再检查,可以dfs,可以bfs,还可以并查集
#include <cstdio> #include <cstring> char maze[12][12]; bool vis[12][12]; bool dfs(int r, int c) { vis[r][c] = true; if(maze[r][c] == '.') return true; if(maze[r][c] == 'x') return false; if(!vis[r + 1][c] && maze[r + 1][c] && dfs(r + 1, c)) return true; if(!vis[r - 1][c] && maze[r - 1][c] && dfs(r - 1, c)) return true; if(!vis[r][c + 1] && maze[r][c + 1] && dfs(r, c + 1)) return true; if(!vis[r][c - 1] && maze[r][c - 1] && dfs(r, c - 1)) return true; return false; } bool judge() { for(int i = 1; i <= 9; i++) for(int j = 1; j <= 9; j++) { if(maze[i][j] != 'o') continue; memset(vis, false, sizeof(vis)); if(!dfs(i, j)) return true; } return false; } bool solve() { for(int i = 1; i <= 9; i++) for(int j = 1; j <= 9; j++) { if(maze[i][j] != '.') continue; maze[i][j] = 'x'; if(judge()) return true; maze[i][j] = '.'; } return false; } int main() { int T; scanf("%d", &T); for(int ca = 1; ca <= T; ca++) { memset(maze, 0, sizeof(maze)); for(int i = 1; i <= 9; i++) scanf("%s", maze[i] + 1); if(solve()) printf("Case #%d: Can kill in one move!!!\n", ca); else printf("Case #%d: Can not kill in one move!!!\n", ca); } return 0; }
相关文章推荐
- goke 交叉编译gdb
- (EM算法)The EM Algorithm
- PS设计漂亮的个人透明背景LOGO添加到直播间
- django log(续 续)
- Google 扩张的法门
- <15> go string_formatting
- go的学习资料
- Google Earth API 替换方案
- Got the Best Employee of the year 2015 Star Award
- Go学习日记
- go lang singleton模式
- HOTPOWER.【专注游戏界面外包】/接游戏界面外包/logo外包/icon
- django性能与优化
- 117 Posted by seenagape on June 23, 2012 Leave a comment (0) Go to comments The BACKUP_TAPE_IO_SLAVE
- 浅析goto语句以及longjmp函数
- IntelliJ IDEA开发golang环境配置
- SAE 配置预装 django1.8.3中出现的问题
- Golang同步:条件变量和锁组合使用
- 关于DragonBoard 410c的串口转usb连接
- Go struct