南邮 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"); } }
相关文章推荐
- 三证是什么?
- Codeforces Round #Pi (Div. 2) A B
- C#开发winform中OpenFileDialog的运用还可以多选
- 南邮 OJ 1492 Nasty Hacks
- ADB not responding. If you'd like to retry, then please manually kill “adb.exe” and click 'Restart'
- 南邮 OJ 1484 烧饼重叠问题
- NSArray和NSMutableArray
- 南邮 OJ 1469 求和
- typeof() test demo
- LeetCode Single Number II
- 利用Mono.Cecil动态修改程序集来破解商业组件
- LeetCode Single Number II
- 【OC06】类目、延展、协议、计时器(连载八)
- linux挂载光盘,U盘
- 登陆界面的完善
- MVC框架介绍
- 文件目录和库
- JavaScript权威指南_149_第15章_脚本化文档_15.10-其他文档特性-可编辑的内容
- Python编译器实现内幕:添加一个新语句
- 南邮 OJ 1464 Text Messaging