HDU 5546 Ancient Go——dfs
2017-04-05 21:46
465 查看
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int dx[] = {0, 0, -1, 1}; const int dy[] = {-1, 1, 0, 0}; char graph[10][10]; int save[10][10], save_point[10][10]; int cnt; bool edge(int x, int y) { if (0 <= x && x < 9 && 0 <= y && y < 9) return true; else return false; } void dfs(int x, int y) { for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (edge(xx, yy) && graph[xx][yy] == '.' && save_point[xx][yy] == 0) { save_point[xx][yy] = 1; cnt++; } } for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (edge(xx, yy) && graph[xx][yy] == 'o' && save[xx][yy] == 0) { save[xx][yy] = 1; dfs(xx, yy); } } } int main() { int T; scanf("%d", &T); for (int kase = 1; kase <= T; kase++) { getchar(); for (int i = 0; i < 9; i++) { getchar(); for (int j = 0; j < 9; j++) { graph[i][j] = getchar(); } } memset(save, 0, sizeof(save)); bool ok = false; for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if (graph[i][j] == 'o' && save[i][j] == 0) { save[i][j] = 1; cnt = 0; memset(save_point, 0, sizeof(save_point)); dfs(i, j); if (cnt == 1) { ok = true; i = 10; break; } } } } if (ok) printf("Case #%d: Can kill in one move!!!\n", kase); else printf("Case #%d: Can not kill in one move!!!\n", kase); } return 0; }
相关文章推荐
- 组队赛2(B/G——Ancient Go)HDU - 5546 (dfs搜索)
- hdu 5546 Ancient Go 枚举 DFS
- hdu 5546 Ancient Go(2016ccpc) 暴力DFS
- HDU 5546 Ancient Go (dfs)
- HDU~5546 Ancient Go(暴力dfs)
- HDU 5546 Ancient Go(DFS)
- hdu 5546 Ancient Go(dfs)
- hdu 5546 Ancient Go【dfs】【思维】
- hdu 5546 Ancient Go(dfs)
- HDU 5546 Ancient Go (dfs)
- [HDOJ] 5546 Ancient Go [DFS]
- hdu 5546 Ancient Go(bfs+模拟)
- 2015 南阳 CCPC hdu 5546 Ancient Go(DFS,暴力)
- HDU 5546 Ancient Go (搜索)
- hdu 5546 Ancient Go(★)
- Ancient Go HDU - 5546
- HDU 5546 Ancient Go 搜索
- The 2015 China Collegiate Programming Contest G. Ancient Go hdu 5546
- hdu 5546 Ancient Go
- HDOJ 5546 Ancient Go(qwb铜牌题 DFS搜索)