【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\)张按任意顺序排列,取出两个乘号相邻和乘法在边界上的非 ...
随机推荐
- qmake的使用
[TOC] 本文由乌合之众 lym瞎编,欢迎转载 blog.cnblogs.net/oloroso 本文由乌合之众 lym瞎编,欢迎转载 my.oschina.net/oloroso *** 还是先说 ...
- [黑科技]bit reverse
写FFT的时候yy出来了这个bit reverse...时间复杂度O(n),常数大概是(a[x>>1]>>1)|((x&1)<<26)的二分之一(-O3下) ...
- ubuntu添加sudo权限
ubuntu有时候没有开通sudo功能,有些操作只能切换到root进行,很不方便. 1.切换到root su root 2.打开suduers文件 gedit /etc/sudoers 3.找到下面这 ...
- etcd相关资料
<1>etcd:从应用场景到实现原理的全方位解读 http://www.infoq.com/cn/articles/etcd-interpretation-application-scen ...
- ubuntu14.04 server安装gnome-desktop
You can install the default Ubuntu desktop by executing the following: sudo apt-get install ubuntu-d ...
- CLR via C# 随记
使用C# 编译器的方法: 1.csc.exe位于C:\Windows\Microsoft.NET\Framework\vxxxxx下面,将对应版本的路径配置到环境变量path中,如将";C: ...
- 手动编译并运行Java项目的过程
现在Java开发基本上就是IDE调试,如果跨平台打个jar包过去运行一般就可以了,但是有些情况比如需要引入外部依赖的时候,这个时候是不能直接运行的,还需要引入一些外部的参数,并不是简单的javac和j ...
- CodeSnippetsLibrary的使用方法
在项目开发中,我们经常可以看到如下所示的代码: @property (nonatomic, copy) NSString *isbatchapprove; @property (nonatomic, ...
- 【leetcode】Same Tree(easy)
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- java判断身份证有效性
import java.util.Calendar; public class CertNoUtil { public static boolean vIDNumByRegex(String idNu ...