UVA - 10935:Throwing cards away I (简单模拟)
题目大意
桌上有一叠牌,自上而下编号为1~n。若桌上牌数大于1张,那么丢弃一张顶部牌后,再将现在的顶部牌移到最后。要求给出模拟过程和最终剩余的牌号
思路分析
典型队列模拟,丢弃即出队,移到最后即入队,但队列大小为1时停止操作
注意点
- 注意n=1时特例,
Discarded cards:后无需空格
#include<bits/stdc++.h>
using namespace std;
int n;
int main() {
while (cin >>n && n != 0) {
printf("Discarded cards:");
queue<int> q;
for (int i = 1; i <= n; i ++) q.push(i);
while (q.size() != 1) {
printf("%s%d", q.front() == 1 ? " " : ", ", q.front()); // 第一个退出无输出,
q.pop();
q.push(q.front()); q.pop(); // 头入队后删除
}
printf("\nRemaining card: %d\n", q.front());
}
return 0;
}
UVA - 10935:Throwing cards away I (简单模拟)的更多相关文章
- UVa 10935 - Throwing cards away I (队列问题)
原题 Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the to ...
- Uva 10935 Throwing cards away I
题目意思:有N张牌,标号为1~N,且牌以叠好,从上到小就是标号1-N的牌,只要牌堆数量大于等于2的时候,就采取如下操作:将最上面的牌扔掉(即离开牌堆).刚才那张牌离开后,再将新的最上面的牌放置于牌堆最 ...
- UVa 10935 Throwing cards away I【队列】
题意:给出 n张牌,从上往下编号依次为1到n,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌. 模拟队列的操作------- #inclu ...
- uva 10935 throwing cards away <queue>
Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n ...
- 【UVA】10935 Throwing cards away I(STL队列)
题目 题目 分析 练习STL 代码 #include <bits/stdc++.h> using namespace std; int main() { int n; wh ...
- UVA 10940 Throwing cards away II
题意略: 先暴力打表发现规律 N=1 ans=1N=2 ans=2N=3 ans=2N=4 ans=4N=5 ans=2N=6 ans=4N=7 ans=6N=8 ans=8N=9 ans=2N=10 ...
- UVa---------10935(Throwing cards away I)
题目: Problem B: Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 ...
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...
- POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径)
POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / ...
- HDU 4772 Zhuge Liang's Password (简单模拟题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4772 题面: Zhuge Liang's Password Time Limit: 2000/1000 ...
随机推荐
- Axure实战应用:Axure设计可视化大屏!
Axure是一款功能强大的原型设计工具,可以用于设计可视化大屏.设计一个有效的可视化大屏需要考虑多个方面,包括布局规划.信息展示.交互设计等. 以下是一个详细的描述,希望对你有所帮助. 第一部分:可视 ...
- Codeforces Round 906 (Div. 2)A-E1
A. Doremy's Paint 3 记数组中数的种类数为\(k\),当\(k=1\)时,答案为\(yes\):当\(k=2\)时,记两个种类的数的个数差为\(d\),当\(d≤1\)时,答案为\( ...
- Tensorflow2.0实现VGG13
导入必要的库: import os import tensorflow as tf from tensorflow import keras from tensorflow.keras import ...
- K8S核心技术
一.命令行工具Kubectl kubectl 是 Kubernetes 集群的命令行工具,通过 kubectl 能够对集群本身进行管理,并能 够在集群上进行容器化应用的安装部署 1.基本语法 kube ...
- 【2020】装了VirtualBox后VMware Workstation无法使用SSH连接Centos的解决方法
装了个VirtualBox,然后发现无法使用Xshell远程Vmware中的centos了,一开始感觉是虚拟网卡冲突了,发现把VirtualBox的虚拟网卡禁用就可以使用,但是好麻烦啊??每次我特么要 ...
- 【UniApp】-uni-app-处理项目输入数据(苹果计算器)
前言 上一篇文章完成了项目的基本布局,这一篇文章我们来处理一下项目的输入数据 项目的输入数据主要是通过按键来输入的,所以我们需要对按键进行处理 那么我们就来看一下 uni-app-处理项目输入数据 步 ...
- 华企盾DSC导致wps个人模式无策略组新建的文件仍然加密
解决方法:右键wps安装目录手动解密即可(原因:wps模板被加密导致)
- 集群化部署ZabbixServer
修改Zabbix-agent配置 1.修改配置文件 三台zabbix-Server上操作 vim /etc/zabbix/zabbix_agent2.conf Server=127.0.0.1 改成 ...
- Pytest07-pytest.ini配置文件
1.pytest配置文件 固定名称:pytest.ini 作用域:当前目录及子目录 具体配置功能见下: [pytest] # 01 把命令行参数自动添加到这里 addopts = -s -v --ht ...
- .net Core实战简单文件服务器
首先新建一个ASP.NET Core 项目,选中空的模板,如下图所示 在NuGet包中添加Microsoft.AspNetCore.StaticFiles 添加好以后我们在Startup.cs中添加对 ...