ny714 Card Trick
Card Trick
- 描述
-
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.
- 输入
- 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的更多相关文章
- UESTC 890 Card Trick(DP 纸牌魔术)
题意 给你一些牌 所有正面朝下放桌子上 你选一个起点 翻开那张牌 牌上的数字是几就向前走几步 J,Q,K 都是向前走10步 A向前走11步 知道向前走相应的步数后超过了终点 ...
- HDU 2319 Card Trick (模拟)
题目链接 Problem Description The magician shuffles a small pack of cards, holds it face down and perform ...
- SPOJ 1108 Card Trick 暴力模拟
解释一下样例,因为我觉得这个题意表述的不是很清楚.以第二组样例为例. 牌序为:3 1 4 5 2 第一轮:把 3 放到末尾:1 4 5 2 3,最顶上的牌是1,把1拿走.剩余 4 5 2 3 第二轮: ...
- POJ 2200 A Card Trick(模拟)
题目链接 题意 : 一共52张牌(A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K)花色分别是C,D,H,S ...给助理5张牌,然后助理需要重新排一下次序,把第一张牌给观 ...
- 【HDOJ】2319 Card Trick
水题,STL双端队列. /* 2319 */ #include <iostream> #include <cstdio> #include <cstring> #i ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- interllij idea13 clone及push工程到github上
转自:http://my.oschina.net/okchen/blog/337556 为什么用Intelli J idea 而不是Eclipse?因为我早已无法忍受Eclipse的慢了,搞不好还会奔 ...
- 每日一句英语:怎样回答美国人的How is it going问候语?
和中国人"吃了吗"是一个性质,本质上仅仅是个话题的起始点,而不是真的想知道你吃了没有. 美国人打招呼有几种方式: 不太熟的人:How are you? 一 般说 pretty go ...
- spring 中常用的配置项
1.spring 中常用的配置项 application.properties #端口 server.port=8081 #调试模式 debug=false #上下文 #一般情况下,小项目通常都是在t ...
- poj 2226 二分图 最小点覆盖 , 最大流
题目就是问怎样用最小的板覆盖全部的草地.能够横着放.也能够竖着放,同意一个草地放多个点. 建图方法就是 每一个横向的草地作为X,纵向连续的草地作为Y. X连接Y的边表示, 这里有他们的公共点 ...
- Tomcat之配置HTTPS
1. 在C:\Windows\System32\drivers\etc\hosts文件中新增一条项目web.demo.com,让Tomcat可以通过域名访问: 127.0.0.1 web.demo.c ...
- OpenStack 网络:Neutron 初探
OpenStack Neutron 网络模型 OpenStack nova-network 独立成为单独的组件 Neutron 后,形象的网络模型的多平面网络.混合平面私有网络.如图 3,图 4,图 ...
- HDUOJ--1159Common Subsequence
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 史上最全的iOS面试题及答案,且看且珍藏,错过就没有喽!
1. Object-c的类可以多重继承么?可以实现多个接口么?Category是什么?重写一个类的方式用继承好还是分类好?为什么? 答:Object-c的类不可以多重继承;可以实现多个接口,通过实现多 ...
- 将jar文件转换成exe可执行文件[转]
将jar文件转换成exe可执行文件: exe文件使用方便,而且还可以提高源码及资源的安全性,但同时也失去了java的初衷--跨平台性. 如果你坚持要转换成exe文件,请按以下方式进行: 利用exe4j ...
- JMeter学习笔记---作用域规则
JMeter测试树中既包含遵循分层规则的测试元件(监听器.配置元件.后置处理器.前置处理器.断言.定时器),又包含遵循顺序规则的测试元件(逻辑控制器.采样器),测试人员创建测试计划的同时,实际上就创建 ...