HDU 5546 Ancient Go——dfs
#include #include #include #include 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;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~