网址如下:
P7012 [CERC2013] Draughts - 洛谷 | 计算机科学教育新生态
有点坑了,白棋不止一个,而题目说“你会得到一个白棋的位置”
总的来说就是dfs硬做
代码如下:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;const int maxn = 10;char board[maxn][maxn];
int _x[maxn * maxn], _y[maxn * maxn], ans, cnt;
int m_x[4]{1, 1, -1, -1};
int m_y[4]{1, -1, 1, -1};void init(void){ans = 0;cnt = 0;
}
void input(void){char c; getchar();for(int i = 0; i < maxn; i++){for(int j = 0; j < maxn; j++){c = getchar();if(c == 'W'){_x[cnt] = i; _y[cnt++] = j;}board[i][j] = c;}getchar();}
}
bool is_out(int x, int y){if(x < 0 || y < 0 || x >= maxn || y >= maxn) return true;return false;
}
void dfs(int x, int y, int d){ans = max(ans, d);for(int i = 0; i < 4; i++){int tx = x + m_x[i], ty = y + m_y[i];if(is_out(tx, ty) || board[tx][ty] != 'B') continue;int ttx = tx + m_x[i], tty = ty + m_y[i];if(is_out(ttx, tty) || board[ttx][tty] != '#') continue;board[tx][ty] = '#';dfs(ttx, tty, d + 1);board[tx][ty] = 'B';}
}int main(void)
{int T; scanf("%d", &T); getchar();while(T--){init(); input();if(cnt){for(int i = 0; i < cnt; i++){board[_x[i]][_y[i]] = '#'; dfs(_x[i], _y[i], 0); board[_x[i]][_y[i]] = 'W';}}printf("%d\n", ans);}return 0;
}