POJ-3032 Card Trick
来源:互联网 发布:学粤语歌软件 编辑:程序博客网 时间:2024/05/16 13:45
原题链接
Memory Limit: 65536KTotal Submissions: 4096
Accepted: 2931
Description
The magician shuffles a small pack of cards, holds it face down and performs the following procedure:
- 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.
- 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.
- Three cards are moved one at a time…
- 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
245
Sample Output
2 1 4 33 1 4 5 2
最后的排列肯定是1 2 3...n,所以从结果开始反向模拟。
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>#include <stack>#include <queue> #include <cmath>#include <algorithm>#define maxn 10005 #define INF 1e9typedef long long ll;using namespace std;int num[20];int main(){//freopen("in.txt", "r", stdin); int t;scanf("%d", &t);while(t--){int n;scanf("%d", &n);for(int i = 1; i <= n; i++) num[i] = i; for(int i = n-1; i >= 1; i--){ int h = i % (n - i + 1); while(h--){ int d = num[n]; for(int j = n-1; j >= i; j--) num[j+1] = num[j]; num[i] = d; } } printf("%d", num[1]); for(int i = 2; i <= n; i++) printf(" %d", num[i]); puts("");}return 0;}
- POJ,3032,Card Trick
- poj 3032 Card Trick
- POJ 3032Card Trick
- POJ-3032 Card Trick
- POJ-3032 Card Trick
- POJ-3032 Card Trick【模拟】
- POJ 一 3032 Card Trick
- E -- POJ 3032 Card Trick
- poj 3032 nyoj 714 Card Trick
- POJ 3032 Card Trick 纸牌顺序
- poj 3032.Card Trick
- Card Trick pku 3032
- poj 2200 A Card Trick(模拟)
- ACM篇:POJ 2200 --A Card Trick
- Card Trick
- Card Trick
- POJ 3032 Card Trick(较好模拟题,双向队列deque)
- PKU3032 Card Trick
- SpringMVC框架学习(1)--执行原理 及 xml注解配置说明
- Exynos4412 内核移植(六)—— 设备树解析
- 泰克DPO4034B余晖模式
- 顺序建立链表(2116)
- Exynos4412 内核移植(五)—— 驱动的移植
- POJ-3032 Card Trick
- Attribute is missing the Android namespace prefix
- python生成器表达式
- VS2010 编译 64bit的GDAL 无法解析外部符号的问题
- Exynos4412 内核移植(四)—— MMU 相关知识解析
- 【C】C语言输入输出缓冲区
- iOS百度地图 Demo
- RDD:基于内存的集群计算容错抽象
- 树状数组拓展笔记