Card Trick

题目描述

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到n,问手中扑克牌最初的顺序

程序代码:

#include<stdio.h>
int main()
{int n,i,j,k,t,T;int a[15];scanf("%d",&T);while(T--){scanf("%d",&n);for(i=n;i>0;i--){a[i]=i;for(j=1;j<=i;j++){t=a[n];for(k=n;k>i;k--)a[k]=a[k-1];a[i]=t;}}for(i=1;i<=n;i++)printf("%d ",a[i]);printf("\n");}return 0;
}

程序代码

Card Trick(模拟)相关推荐

  1. NYOJ 714 Card Trick

    Card Trick 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 The magician shuffles a small pack of cards, holds ...

  2. Card Trick

    Card Trick 时间限制: 1 Sec 内存限制: 128 MB 题目描述 The magician shuffles a small pack of cards, holds it face ...

  3. POJ 超详细分类

    POJ 各题算法 1000    A+B Problem            送分题     49%    2005-5-7 1001    Exponentiation         高精度   ...

  4. 杭电oj题目题型分类(转)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  5. HDOJ题目分类大全

    版权声明:本文为博主原创文章,欢迎转载,转载请注明本文链接! https://blog.csdn.net/qq_38238041/article/details/78178043 杭电里面有很多题目, ...

  6. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  7. 杭电OJ题目分类(转载)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  8. 初学者acm的练习题指南

    上机练习题参考题 忘了在哪找的啦~~希望对大家有帮助呦 <!--[if !supportLists]-->1.    <!--[endif]-->Programming Bas ...

  9. HOJ题目分类//放这儿没事刷刷学算法!嘻嘻!

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

最新文章

  1. C语言学习 - 字节对齐
  2. 前端如何高效的与后端协作开发
  3. python画图库哪个好_机器学习基础5--python画图库matplotlib(上)
  4. ECMAScript 发展历史
  5. Java Kafka 简单示例
  6. 第六章 副词(Les adverbes )
  7. php连接mysql执行sql语句_php+mysql 连接服务器、数据库以及执行SQL语句的类库
  8. 卷积过滤器的宽度_卷积神经网络简析
  9. WebStrom如何创建项目,为什么我开始选择HTML5到自定义路径报错
  10. 选课系统服务器,选课系统概要设计
  11. 京东羚珑页面可视化平台介绍
  12. AIR202/208使用AT指令方式连接MQTT调试笔记
  13. delphi7中的局部变量和全局变量
  14. 130 个相见恨晚的超实用网站
  15. pr基本图形模板无法使用_Pr基本图形板块教程 Premiere Pro CC Essential Graphics
  16. Axure8实现最常见的左侧动态导航
  17. inno setup将exe应用打包成——安装包
  18. Dell EMC VxRail
  19. 微信多开软件苹果版_快手充值快币微信充值苹果版;
  20. Python和JavaScript间代码转换4个工具

热门文章

  1. 为GridView-Delete列添加确认对话框(2种方法)
  2. 卷积交织/解交织C++程序
  3. python+Django框架运用(一)
  4. Zabbix监控nginx status
  5. visual stdio 工程 宏
  6. C语言文件操作解析(一)
  7. 探秘Spring AOP(上)
  8. Web前后端交互总结
  9. VMware虚拟机文件
  10. kafka python教程_由Flink与Kafka实践探究Kafka的两个问题