【sicily】卡片游戏
卡片游戏
Time Limit: 1sec Memory Limit:32MB
Description
桌上有一叠牌,从第一张牌(即位于顶面的牌)开始从上往下依次编号为1~n。当至少还剩两张牌时进行以下操作:把第一张牌扔掉,然后把新的第一张放到整叠牌的最后。输入n,输出每次扔掉的牌,以及最后剩下的牌。
Input
第一行为一个整数t(0<t<40),表示测试用例个数。以下t行每行包含一个整数n(0<n<40),为一个测试用例的牌数。
Output
为每个测试用例单独输出一行,该行中依次输出每次扔掉的牌以及最后剩下的牌,每张牌后跟着一个空格。
Sample Input
Copy sample input to clipboard
2
7
4
Sample Output
1 3 5 7 4 2 6
1 3 2 4
代码实现:
//队列的应用
#include<iostream>
#include<stack>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm> using namespace std;
queue<int>card;
int main(){
int t;
cin>>t;
int n;
while(t--){
cin>>n;
for(int i=1; i<=n; i++){
card.push(i);
}
while(!card.empty()){
cout<<card.front()<<" ";
card.pop();
card.push(card.front());
card.pop();
}
cout<<endl;
}
}
【sicily】卡片游戏的更多相关文章
- Sicily 1931. 卡片游戏
题目地址:1931. 卡片游戏 思路: 纯属数据结构中队列的应用,可以练练手. 具体代码如下: #include <iostream> #include <queue> usi ...
- 卡片游戏(hdu4550)贪心
卡片游戏 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submi ...
- nyoj905 卡片游戏
卡片游戏 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 小明最近宅在家里无聊,于是他发明了一种有趣的游戏,游戏道具是N张叠在一起的卡片,每张卡片上都有一个数字,数字 ...
- NYOJ 905 卡片游戏
卡片游戏 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描写叙述 小明近期宅在家里无聊.于是他发明了一种有趣的游戏.游戏道具是N张叠在一起的卡片,每张卡片上都有一个数字,数字 ...
- Java实现 LeetCode 822 翻转卡片游戏(暴力)
822. 翻转卡片游戏 在桌子上有 N 张卡片,每张卡片的正面和背面都写着一个正数(正面与背面上的数有可能不一样). 我们可以先翻转任意张卡片,然后选择其中一张卡片. 如果选中的那张卡片背面的数字 X ...
- hdu 4550 卡片游戏 贪心
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4550 题意:有n(n <= 100)个0~9之间的卡片,从左往右将卡片放到之前的卡片最左边或者最 ...
- [Swift]LeetCode822. 翻转卡片游戏 | Card Flipping Game
On a table are N cards, with a positive integer printed on the front and back of each card (possibly ...
- [LeetCode] Card Flipping Game 翻卡片游戏
On a table are N cards, with a positive integer printed on the front and back of each card (possibly ...
- 【XSY1591】卡片游戏 DP
题目描述 有标有数字为\(1\)~\(9\)的卡片各\(a_1,a_2\cdots a_9\)张,还有标有乘号的卡片\(m\)张.从中取出\(n\)张按任意顺序排列,取出两个乘号相邻和乘法在边界上的非 ...
随机推荐
- Struts2中的OGNL通配符
<action name="*_*" class="action.{1}Action" method="{2}"> 匹配,第一个 ...
- 将 JAR 转为 EXE – EXE4J 的使用教程(第一期)(转载)
http://www.iteknical.com/convert-jar-to-exe-phase-i-exe4j-tutorial/
- jquery对url中的中文解码
项目中要实现一个select选择器选择后跳转url,并保存selected的值. url是用get来传递参数,所以考虑加载新页面时,读取参数值,并赋值到select中. 但是由于url的参数使用的是中 ...
- PHP: How to print a debug log?
file_put_contents('php://stderr', print_r("hello ", TRUE)); 转自: http://stackoverflow.com/q ...
- ubuntu update dns server
edit: /etc/resolvconf/resolv.conf.d/base nameserver 114.114.114.114 execute this: $ resolvconf -u f ...
- 【IDEA】IDEA 如何设置编辑器字体大小
intellij idea 如何更改编辑器文本字体和大小 换上了intellij idea之后,第一件事就是想要改变下文字字体,因为在我这个27寸的2k分辨率的屏幕上,文字显然太小了. intel ...
- 【leetcode】Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending ord ...
- 如何用 Robotframework 来编写优秀的测试用例
介绍 这篇文档将会是一篇在「高层面」的怎么用 Robotframework 来编写优秀测试用例的原则.至于如何使用 Robotframework 来与您的待测试系统相作用这样的细节讨论是不包含在这篇文 ...
- centos6.5 iptables结合ipset批量屏蔽ip
安装ipset yum install ipset #创建ip地址集合 ipset create bansms hash:net 查找访问了“getVerificationCode”并且次数大于10次 ...
- nyoj305_表达式求值
表达式求值 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简单的函数求值,比如,它知道函数min ...