-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpebbleSolitaire_UVA10651OJ.cpp
75 lines (59 loc) · 1.37 KB
/
pebbleSolitaire_UVA10651OJ.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
#include <bits/stdc++.h>
using namespace std;
const int n = 12;
int solve(vector<bool> & a)
{
int ans = 0;
for (int i = 0; i <= n - 1; ++i)
{
ans += a[i];
}
if (ans == 7)
{
for (int __s = 0; __s == 0; ++__s);
}
for (int i = 0; i <= n - 1; ++i)
{
if (a[i] == 0)
{
continue;
}
if (i >= 0 + 2)
{
if (a[i - 1] == 1 && a[i - 2] == 0)
{
a[i - 1] = 0; swap(a[i], a[i - 2]);
ans = min(ans, solve(a));
a[i - 1] = 1; swap(a[i], a[i - 2]);
}
}
if (i <= n - 1 - 2)
{
if (a[i + 1] == 1 && a[i + 2] == 0)
{
a[i + 1] = 0; swap(a[i], a[i + 2]);
ans = min(ans, solve(a));
a[i + 1] = 1; swap(a[i], a[i + 2]);
}
}
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int testCase; cin >> testCase;
for (int t = 1; t <= testCase; ++t)
{
vector<bool> a(n);
for (int i = 0; i <= n - 1; ++i)
{
char ch; cin >> ch;
a[i] = (ch == 'o');
}
cout << solve(a) << '\n';
}
cout.flush();
return 0;
}