博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ny714 Card Trick
阅读量:6818 次
发布时间:2019-06-26

本文共 1828 字,大约阅读时间需要 6 分钟。

Card Trick

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
描述

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…
样例输入
245
样例输出
2 1 4 33 1 4 5 2 参考代码,用的双端队列写的
1   2 #include
3 #include
4 #include
5 using namespace std; 6 int main() 7 { 8 deque
q; 9 int t,n,a,m,i,k,j;10 cin>>t;11 while(t--)12 {
while(!q.empty())13 q.pop_front();14 cin>>n;15 int mm=n-1,kk=2;16 q.push_front(n);17 for(i=n-1;i>=1;i--,mm--,++kk)18 {19 q.push_front(mm);20 for(j=i%kk;j>0;j--)21 {22 q.push_front(q.back());23 q.pop_back();24 }25 }26 for(i=0;i

 

转载于:https://www.cnblogs.com/lovychen/p/3546079.html

你可能感兴趣的文章
[转]Web Api系列教程第2季(OData篇)(二)——使用Web Api创建只读的OData服务
查看>>
linux内核段属性机制【转】
查看>>
eclipse设置系统字体
查看>>
复旦大学考研科目
查看>>
16、Java并发性和多线程-死锁
查看>>
Linux下用netstat查看网络状态、端口状态
查看>>
Java 实现有序链表
查看>>
zoj 1203 Swordfish
查看>>
手机怎么访问电脑服务器上的网页
查看>>
Python帮助函数调试函数 用于获取对象的属性及属性值
查看>>
制做rpm包工具fpm安装
查看>>
POJ 2253-Frogger (Prim)
查看>>
哪种锻炼方式最能让程序猿远离亚健康? - 强烈推荐
查看>>
基于Metronic的Bootstrap开发框架经验总结(15)-- 更新使用Metronic 4.75版本
查看>>
Kafka(二)-- 安装配置
查看>>
MapReduce 图解流程
查看>>
[LeetCode] Wildcard Matching
查看>>
深入解析Windows窗体创建和消息分发
查看>>
AIX下RAC搭建 Oracle10G(六)dbca建库
查看>>
vs code 快捷键中英文对照
查看>>