-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrookedOJ.cpp
93 lines (84 loc) · 2.15 KB
/
rookedOJ.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
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int solve(vector<vector<char>> a, int lvl)
{
int size = a[0].size(), maxCount = 0;
for (int y = 0; y <= size - 1; ++y)
{
for (int x = 0; x <= size - 1; ++x)
{
if (a[y][x] != 'X' && a[y][x] != 'a')
{
vector<vector<char>> temp = a;
temp[y][x] = 'X';
for (int p = y - 1; p >= 0; --p)
{
if (temp[p][x] == 'X')
{
break;
}
temp[p][x] = 'a';
}
for (int p = y + 1; p <= size - 1; ++p)
{
if (temp[p][x] == 'X')
{
break;
}
temp[p][x] = 'a';
}
for (int p = x - 1; p >= 0; --p)
{
if (temp[y][p] == 'X')
{
break;
}
temp[y][p] = 'a';
}
for (int p = x + 1; p <= size - 1; ++p)
{
if (temp[y][p] == 'X')
{
break;
}
temp[y][p] = 'a';
}
maxCount = max(maxCount, solve(temp, lvl + 1) + 1);
}
}
}
return maxCount;
}
int main()
{
while (true)
{
int size = 0;
cin >> size;
if (size == 0)
{
break;
}
vector<vector<char>> a(size, vector<char>(size));
for (int y = 0; y <= size - 1; ++y)
{
for (int x = 0; x <= size - 1; ++x)
{
cin >> a[y][x];
}
}
cout << solve(a, 0) << '\n';
}
return 0;
}