Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Feb 17, 2019
1 parent 81b83d0 commit d00a352
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 1 deletion.
2 changes: 1 addition & 1 deletion myCpps/!-OJcreater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using namespace std;

//***************************************
const string CPPfile = "liftHopping_UVA10801"; //*
const string CPPfile = "pebbleSolitaire_UVA10651"; //*
//***************************************

ifstream fin(CPPfile + ".cpp");
Expand Down
73 changes: 73 additions & 0 deletions myCpps/pebbleSolitaire_UVA10651.cpp
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;
}
3 changes: 3 additions & 0 deletions myCpps/pebbleSolitaire_UVA10651.in
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
2 changes: 2 additions & 0 deletions myCpps/pebbleSolitaire_UVA10651.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
1
75 changes: 75 additions & 0 deletions myCpps/pebbleSolitaire_UVA10651OJ.cpp
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;
}

0 comments on commit d00a352

Please sign in to comment.