Created
September 12, 2012 12:47
-
-
Save logicmd/3706377 to your computer and use it in GitHub Desktop.
Card Stacking
This file contains hidden or 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
/************************************************************************* | |
Author: logicmd | |
Created Time: 2012/9/12 19:12:56 | |
File Name: CardStacking.cpp | |
Description: | |
************************************************************************/ | |
#include <cassert> | |
#include <iostream> | |
#include <set> | |
#include <queue> | |
#include <cstdio> | |
#include <string> | |
#include <utility> | |
#include <algorithm> | |
using namespace std; | |
queue<int> q; | |
set<int> good; | |
void build(int k) | |
{ | |
//q = new queue<int>(); | |
//good = new set<int>(); | |
for(int i = 1; i <= k; i++) | |
{ | |
q.push(i); | |
} | |
} | |
void toButtom(int p) | |
{ | |
for(int i = 1; i <= p; i++) | |
{ | |
q.push(q.front()); | |
q.pop(); | |
} | |
} | |
int main() | |
{ | |
int n, p, k; | |
cin >> n >> k >> p; | |
build(k); | |
int c = 0; | |
while(q.size() != 0) | |
{ | |
int temp = q.front(); | |
q.pop(); | |
toButtom(p); | |
if(++c % n == 0) | |
{ | |
good.insert(temp); | |
} | |
} | |
for(set<int>::iterator si = good.begin(); si != good.end(); si++) | |
{ | |
cout << *si << endl; | |
} | |
//system("PAUSE"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment