-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva00260.cpp
72 lines (58 loc) · 1.5 KB
/
uva00260.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <climits>
#include <cmath>
#include <set>
#include <bitset>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <tuple>
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
using namespace std;
int N;
char game[200][200];
bool visited[200][200];
const int dr[] = {-1, -1, 0, 0, 1, 1};
const int dc[] = {-1, 0, -1, 1, 0, 1};
bool dfs(int row, int col){
visited[row][col] = true;
if(row == N-1) return true;
int nextRow, nextCol;
bool black = false;
for(int i = 0; i < sizeof(dr)/sizeof(int); ++i){
nextRow = row + dr[i];
nextCol = col + dc[i];
if(nextRow < 0 || nextRow >= N
|| nextCol < 0 || nextCol >= N
|| visited[nextRow][nextCol]
|| game[nextRow][nextCol] == 'w') continue;
black |= dfs(nextRow, nextCol);
}
return black;
}
int main(){ _
int count = 0;
while(cin >> N){
if(N == 0) break;
else cout << ++count << " ";
for(int i = 0; i < N; ++i){
for(int j = 0; j < N; ++j){
cin >> game[i][j];
}
}
memset(visited, false, sizeof visited);
bool black = false;
for(int i = 0; i < N; ++i){
if(!visited[0][i]) black |= dfs(0, i);
}
if(black) cout << "B" << endl;
else cout << "W" << endl;
}
return 0;
}