-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81b83d0
commit d00a352
Showing
5 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("pebbleSolitaire_UVA10651.in"); | ||
ofstream fout("pebbleSolitaire_UVA10651.out"); | ||
|
||
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() | ||
{ | ||
int testCase; fin >> testCase; | ||
for (int t = 1; t <= testCase; ++t) | ||
{ | ||
vector<bool> a(n); | ||
for (int i = 0; i <= n - 1; ++i) | ||
{ | ||
char ch; fin >> ch; | ||
a[i] = (ch == 'o'); | ||
} | ||
|
||
fout << solve(a) << '\n'; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
2 | ||
oo-o-o-o-o-o | ||
o-o-o-o-o-oo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
|