Skip to content

Instantly share code, notes, and snippets.

@ik11235
Created December 12, 2014 15:19
Show Gist options
  • Save ik11235/cbe56ca1754bfadc732b to your computer and use it in GitHub Desktop.
Save ik11235/cbe56ca1754bfadc732b to your computer and use it in GitHub Desktop.
class ShufflingCardsDiv2 {
public:
string shuffle(vector<int> permutation) {
const int n=permutation.size();
vector<int> ga,gb;
for(int i=0;i<n;i++)
{
if(i%2==0)
ga.push_back(permutation[i]);
else
gb.push_back(permutation[i]);
}
sort(ga.begin(),ga.end());
sort(gb.begin(),gb.end());
vector<int> a,b;
int ac=0;
int bc=0;
for(int i=1;i<=n;i++)
{
if(i<=n/2)
a.push_back(i);
else
b.push_back(i);
}
for(int i=0;i<ga.size();i++)
{
if(find(a.begin(),a.end() ,ga[i])!=a.end())
ac++;
if(find(b.begin(),b.end() ,ga[i])!=b.end())
bc++;
}
if(ac==(n/4)+(n/2)%2)
return "Possible";
else
return "Impossible";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment