南邮 OJ 1494 Card Trick
来源:互联网 发布:个人名片设计软件 编辑:程序博客网 时间:2024/06/18 16:45
Card Trick
总提交 : 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");}}
- 南邮 OJ 1494 Card Trick
- Card Trick
- Card Trick
- Card Trick pku 3032
- PKU3032 Card Trick
- poj 3032.Card Trick
- POJ3032 Card Trick
- NYOJ 714 Card Trick
- NYOJ 714 Card Trick
- POJ,3032,Card Trick
- 1018 A Card Trick
- poj 3032 Card Trick
- NYOJ 714 Card Trick
- NYOJ714-Card Trick
- POJ 3032Card Trick
- 2485. Card Trick
- 714 Card Trick
- 1018. A Card Trick
- UI04_Touch
- 南邮 OJ 1492 Nasty Hacks
- java ClassLoader 详解
- UI_UILTView
- 三证是什么?
- 南邮 OJ 1494 Card Trick
- C#文件操作总结
- UI04_Target-Action
- 南邮 OJ 1498 Honeycomb Walk
- UI03_UIViewController视图控制器
- 杭电ACM 2099:整除的尾数
- CodeForces 567- Berland National Library
- 控件出不来?看我的就够了
- 不平衡数据集下的SVM算法研究