-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path260.cpp
119 lines (108 loc) · 3.25 KB
/
260.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> board;
int visited[201][201];
int aux_i[] = {-1, -1, 0, 0, 1, 1};
int aux_j[] = {-1, 0, -1, 1, 0, 1};
// bool dsfWhite(int x, int y, bool &win){
// int I, J;
// for(int i=0; i<6; i++){
// I = x + aux_i[i];
// J = y + aux_j[i];
// if (I >= 0 && I < n && J >= 0 && J < n && !visited[I][J]){
// if (board[I][J] == 'w'){
// visited[I][J] = 1;
// // cout << "DFS White avanzo a : " << I << " " << J << endl;
// if(J == n-1)
// win = true;
// dsfWhite(I, J, win);
// }
// }
// }
// if(win){
// return true;
// } else {
// return false;
// }
// }
bool dfsBlack(int x, int y, bool &win){
int I, J;
for (int i = 0; i < 6; i++){
I = x + aux_i[i];
J = y + aux_j[i];
if (I >= 0 && I < n && J >= 0 && J < n && !visited[I][J]){
if (board[I][J] == 'b'){
visited[I][J] = 1;
// cout << "DFS Black avanzo a : " << I << " " << J << endl;
if (I == n - 1)
win = true;
dfsBlack(I, J, win);
}
}
}
if (win){
return true;
}else {
return false;
}
}
int main(){
string s;
int cont = 1;
while (scanf("%d", &n)){
if (!n)
break;
bool win = false;
board.clear();
memset(visited, 0, sizeof(visited));
for (int i = 0; i < n; i++)
{
cin >> s;
board.push_back(s);
}
for(int j=0; j<n; j++){
int i = 0;
if(!visited[i][j]){
visited[i][j] = 1;
if (board[i][j] == 'b' && i == 0)
{
if (dfsBlack(i, j, win)){
cout << cont << " " << "B" << endl;
cont++;
break;
}
}
}
}
if(!win){
cout << cont << " " << "W" << endl;
cont++;
}
// for (int i = 0; i < n; i++){
// for (int j = 0; j < n; j++){
// bool win = false;
// if (!visited[i][j]){
// visited[i][j] = 1;
// // cout << "Board["<<i<<"]["<<j<<"] = " << board[i][j] << endl;
// if (board[i][j] == 'w' && j == 0){
// // cout << "DFS White en: " << i << " " << j << endl;
// if (dsfWhite(i, j, win)){
// cout << cont << " " << "W" << endl;
// cont++;
// break;
// }
// }
// else if (board[i][j] == 'b' && i == 0){
// // cout << "DFS Black en: " << i << " " << j << endl;
// if (dfsBlack(i, j, win)){
// cout << cont << " " << "B" << endl;
// cont++;
// break;
// }
// }
// }
// }
}
return 0;
}