2014
01-05

# Card Trick

The magician shuffles a small pack of cards, holds it face down and performs the following procedure:

1.The top card is moved to the bottom of the pack. The new top card is dealt face up onto the table. It is the Ace of Spades.
2.Two cards are moved one at a time from the top to the bottom. The next card is dealt face up onto the table. It is the Two of Spades.
3.Three cards are moved one at a time…
4.This goes on until the nth and last card turns out to be the n of Spades.
This impressive trick works if the magician knows how to arrange the cards beforehand (and knows how to give a false shuffle). Your program has to determine the initial order of the cards for a given number of cards, 1 ≤ n ≤ 13.

On the first line of the input is a single positive integer, telling the number of test cases to follow. Each case consists of one line containing the integer n.

On the first line of the input is a single positive integer, telling the number of test cases to follow. Each case consists of one line containing the integer n.

2
4
5

2 1 4 3
3 1 4 5 2

……

#include<cstdio>
#include<cstring>
#include<deque>
#include<algorithm>
using namespace std;
int ac[110];
deque<int>q; //双向队列模拟

int main()
{
int ncase, n;
scanf("%d", &ncase);
while(ncase--)
{
scanf("%d", &n);
q.push_back(n);
for(int i = n - 1; i >= 1; --i)
{
q.push_back(i);
for(int j = 1; j <= i; ++j)
{
int temp = q.front();
q.push_back(temp);
q.pop_front();
}
}
while(!q.empty())
{
printf("%d ", q.back());
q.pop_back();
}
printf("\n");
}
return 0;
}

1. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！

2. 算法是程序的灵魂，算法分简单和复杂，如果不搞大数据类，程序员了解一下简单点的算法也是可以的，但是会算法的一定要会编程才行，程序员不一定要会算法，利于自己项目需要的可以简单了解。