您的位置:首页 > 其它

南邮 OJ 1494 Card Trick

2015-08-06 08:34 429 查看


Card Trick

时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte

总提交 : 17 测试通过 : 13

比赛描述

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.

输出

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…

样例输入

2

4

5

样例输出

2 1 4 3

3 1 4 5 2

题目来源

Nordic 2006

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

int main(){
int t,n,i;
deque<int> q;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
q.push_front(n);
while(--n){
q.push_front(n);
for(i=0;i<n;i++){
q.push_front(q.back());
q.pop_back();
}
}
printf("%d",q.front());
q.pop_front();
while(!q.empty()){
printf(" %d",q.front());
q.pop_front();
}
printf("\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: