#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;
}
HDU 5546 Ancient Go——dfs
原创
©著作权归作者所有:来自51CTO博客作者软糖酱八号机的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
ACM HDU 3460 Ancient Printer(简单题)
anted to print the teams' names separately on a single paper.Unfortuna
#include i++ java edn ios -
python close文件后刷新
# 文件夹、文件重命名 import os ''' 多文件夹批量更改名称 path:根文件夹位置 dict:更改名称的字典值 ''' def changeDirName(path,dict): '''打开文件夹路径''' os.chdir(path); '''然后获取该文件夹下所有的子文件夹''' files = os.listdir(pa
python close文件后刷新 python intellij idea 文件名 打开文件