河南省第六届大学生程序设计竞赛 F Card Trick
2016-05-26 20:52
357 查看
1627: Card Trick
时间限制: 1 Sec 内存限制: 128 MB提交: 37 解决: 25
[提交][状态]
题目描述
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 k, telling the number of test cases to follow. 1 ≤ k ≤ 10 Each case consists of one line containing the integer n. 1 ≤ n ≤ 13输出
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
提示
来源
河南省第六届大学生程序设计竞赛[提交][状态]
题意:给你n张牌,让你变一个魔术:第1次把上面的1张牌放到底部,然后最上面的牌就是1,然后拿走1。第2次把上面的2张牌依次放到底部,然后最上面的牌就是2,然后拿走2....重复这个过程,直到所有的牌都被拿走。问一开始的牌应该从上到下怎么放,才能完成这个魔术。
算法:逆向思维,从后向前模拟。
相关文章推荐
- 搬瓦工VPS(Centos6_x86)+LNMP+WordPress搭建个人博客/网站
- POJ 1067 威佐夫博弈
- sdut 3272 山理工第七届校赛--字符的变化
- POJ 1067 威佐夫博弈
- 用JS生成MIDI文件(附代码)
- 谁的青春不迷茫
- 【操作系统】linux创建子进程--fork()方法
- GridView属性大全
- Touch panel DTS 分析(MSM8994平台,Atmel 芯片)
- 数组中增加或者删除元素
- Android之Adapter用法总结
- 深入浅出linux内核源代码之双向链表list_head(下):
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结
- RESTful API 设计指南
- 比较java c++ 对象之间的区别(内存)
- Hash函数的安全性
- 排列组合公式 扳子
- sdut 3270 山理工第七届校赛--飞花的鱼塘
- 表单数据提交后,数据库记录显示为问号的解决
- PHP - 简单获取页面内容