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…
样例输入
2
4
5
样例输出
2 1 4 3
3 1 4 5 2
参考代码,用的双端队列写的
 #include<deque>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
deque<int>q;
int t,n,a,m,i,k,j;
cin>>t;
while(t--)
{while(!q.empty())
q.pop_front();
cin>>n;
int mm=n-,kk=;
q.push_front(n);
for(i=n-;i>=;i--,mm--,++kk)
{
q.push_front(mm);
for(j=i%kk;j>;j--)
{
q.push_front(q.back());
q.pop_back();
}
}
for(i=;i<n;i++)
{
cout<<q.front()<<" ";
q.pop_front();
}
cout<<endl;
}
return ;
}

ny714 Card Trick的更多相关文章

  1. UESTC 890 Card Trick(DP 纸牌魔术)

    题意  给你一些牌  所有正面朝下放桌子上   你选一个起点    翻开那张牌   牌上的数字是几就向前走几步   J,Q,K 都是向前走10步  A向前走11步   知道向前走相应的步数后超过了终点 ...

  2. HDU 2319 Card Trick (模拟)

    题目链接 Problem Description The magician shuffles a small pack of cards, holds it face down and perform ...

  3. SPOJ 1108 Card Trick 暴力模拟

    解释一下样例,因为我觉得这个题意表述的不是很清楚.以第二组样例为例. 牌序为:3 1 4 5 2 第一轮:把 3 放到末尾:1 4 5 2 3,最顶上的牌是1,把1拿走.剩余 4 5 2 3 第二轮: ...

  4. POJ 2200 A Card Trick(模拟)

    题目链接 题意 : 一共52张牌(A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K)花色分别是C,D,H,S ...给助理5张牌,然后助理需要重新排一下次序,把第一张牌给观 ...

  5. 【HDOJ】2319 Card Trick

    水题,STL双端队列. /* 2319 */ #include <iostream> #include <cstdio> #include <cstring> #i ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. HOJ题目分类

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

  8. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  9. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. Uubntu14.04下 Hadoop集群环境搭建

    1机器信息 master192.168.3.10 hadoop/ hadoop slave1192.168.3.11 hadoop/ hadoop slave2192.168.3.12 hadoop/ ...

  2. javascript 设计模式

    了解JavaScript设计模式我们需要知道的一些必要知识点:(内容相对基础,高手请跳过) 闭包:关于闭包这个月在园子里有几篇不错的分享了,在这我也从最实际的地方出发,说说我的理解. 1.闭包最常用的 ...

  3. java8 map flatmap

    map: 对于Stream中包含的元素使用给定的转换函数进行转换操作,新生成的Stream只包含转换生成的元素.这个方法有三个对于原始类型的变种方法,分别是:mapToInt,mapToLong和ma ...

  4. COCOS学习笔记--粒子系统

    一.粒子系统的简单介绍 粒子系统是指计算机图形学中模拟特定现象的技术,它在模仿自然现象.物理现象及空间扭曲上具备得天独厚的优势,为我们实现一些真实自然而又带有随机性的特效(如爆炸.烟花.水流)提供了方 ...

  5. 【Linux】echo命令

    用途 echo是用于终端打印的基本命令 说明 只需要使用带双引号的文本,结合echo命令就可以将文本打印在终端. [root@localhost test]# echo "Hello Wor ...

  6. &和&&的一点区别

    &两边的语句都会执行,&&有可能只执行左边的语句. &做位运算与的时候可以更高效的判断一个数字是不是奇数. 1&1 = 1 0&1 = 0 所以和1与结 ...

  7. iOS-按钮单选与多选逻辑处理

    概述 循环创建按钮, 进行按钮单选或者多选的操作. 详细 代码下载:http://www.demodashi.com/demo/10712.html 我们经常会有多行多列按钮的页面, 这个时候我们通常 ...

  8. 深入了解MyBatis参数

    参考1 参考2 参考3

  9. Java中entity(实体类)的写法规范

    在日常的Java项目开发中,entity(实体类)是必不可少的,它们一般都有很多的属性,并有相应的setter和getter方法.entity(实体类)的作用一般是和数据表做映射.所以快速写出规范的e ...

  10. PHP读取大文件的几种方法

    场景:PHP读取超大文件,例如1G的日志文件,我这里使用的是400M的access.log文件 1.使用file直接读取 <?php $starttime=microtime_float(); ...