题目链接:传送门

Problem Description

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.

Input

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.

Output

For each test case, output a line with the correct permutation of the values 1 to n, space separated. The first number showing the top card of the pack, etc…

Sample Input

2

4

5

Sample Output

2 1 4 3

3 1 4 5 2

题目大意:

我们要利用n张牌表演一个魔术,魔术的步骤是这样的:

将开头一张牌移动到最后,接着拿出这堆牌的第一张,这张牌的数字是1,将这张牌丢弃

将开头二张牌移动到最后,接着拿出这堆牌的第一张,这张牌的数字是2,将这张牌丢弃

将开头三张牌移动到最后,接着拿出这堆牌的第一张,这张牌的数字是3,将这张牌丢弃

……

将开头n张牌移动到最后,接着拿出这堆牌的第一张,这张牌的数字是n

问你,假如要成功地表演这个魔术,求这个排列。

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;

int main()
{
    int a,b,c,d,e,f;
    cin>>a;
    while(a--)
    {
        cin>>b;
        queue<int>m;
        int n[20];
        m.push(b);
        for(c=b-1;c>0;c--)
        {
            m.push(c);
            for(d=0;d<c;d++)
            {
                e=m.front();
                m.pop();
                m.push(e);
            }
        }
        f=0;
        while(!m.empty())
        {
            e=m.front();
            m.pop();
            n[f++]=e;
        }
        for(d=f-1;d>0;d--)
            cout<<n[d]<<" ";
        cout<<n[0]<<endl;
    }
    return 0;
}