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 ...
随机推荐
- iOS程序入口结构
盛年不重来,一日难再晨.及时宜自勉,岁月不待人. 1. 程序入口 在我们开始开发app的时候,第一步往往是通过设置AppDelegate.m的代理方法开始写一些启动的东西,然后再通过控制器View ...
- 【已解决】【Tensorflow2.12.0版本以后合并CPU和GPU版】Tensorflow-gpu==2.12.0 安装失败解决办法
直接上解决方式,需要知道原因的看后文. 直接安装 tensroflow,从 2022 年 12 月起 tensorflow-gpu 已经合并到 tensorflow 包中了 pip install t ...
- springcloud+nacos项目启动后,登陆连接服务器时超时:Connection timed out no further information
问题现象:项目启动后,登陆连接服务器时超时:Connection timed out no further information 192.168.42.190:4004 原因:我的配置有问题,在na ...
- [CF1325E] Ehab's REAL Number Theory Problem
Ehab's REAL Number Theory Problem 题目描述 You are given an array $ a $ of length $ n $ that has a speci ...
- [ABC263A] Full House
Problem Statement We have five cards with integers $A$, $B$, $C$, $D$, and $E$ written on them, one ...
- 目标检测工具安装使用--labelImg
如果想要在深度学习中训练我们自己的模型,就得对图片进行标注.labelImg是一个超级方便的目标检测图片标注工具,打开图片后,只需用鼠标框出图片中的目标,并选择该目标的类别,便可以自动生成voc格式的 ...
- Java中获取Class对象的三种方式
在Java中,我们经常需要获取某个类的Class对象,以便进行反射操作.动态加载类或者获取类的信息.本文将介绍Java中获取Class对象的三种常见方式. 1. 使用.class语法 获取Class对 ...
- awk所有常用语法
awk [OPTIONS] PROGRAM FILE... 选项: -F 指定分隔符 -f 引用awk脚本 -v VAR=VALUE 定义一个变量传递给PROGRAM,但是这里的变量BEGIN读不了, ...
- R6900 R7000刷梅林 AImesh组网
本文作者: Colin本文链接: https://www.colinjiang.com/archives/netgear-r6900-flash-merlin-rom.html 然后开始讲正题,刷梅林 ...
- zabbix+oracle环境部署
oracle11安装完成后, 实例名: zbx01 oracle创建zbx01用户:col file_name for a60;set linesize 160;select file_name,ta ...