【UVA】10935 Throwing cards away I(STL队列)
题目
分析
练习STL
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n) && n!=0)
{
queue<int> q;
printf("Discarded cards:");
for(int i=1;i<=n;i++) q.push(i);
while(q.size()!=1)
{
if(q.front()!=1) printf(",");
printf(" %d",q.front()); q.pop();
int x=q.front(); q.pop();
q.push(x);
}
printf("\nRemaining card: %d\n",q.front());
}
return 0;
}
【UVA】10935 Throwing cards away I(STL队列)的更多相关文章
- 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,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌. 模拟队列的操作------- #inclu ...
- Uva 10935 Throwing cards away I
题目意思:有N张牌,标号为1~N,且牌以叠好,从上到小就是标号1-N的牌,只要牌堆数量大于等于2的时候,就采取如下操作:将最上面的牌扔掉(即离开牌堆).刚才那张牌离开后,再将新的最上面的牌放置于牌堆最 ...
- 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】12100 Printer Queue(STL队列&优先队列)
题目 题目 分析 练习STL 代码 #include <bits/stdc++.h> using namespace std; int main() { int t; sc ...
- 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 ...
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...
- 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 top a ...
- Throwing cards away I uva1594
Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the t ...
随机推荐
- 3PC
3PC,是Three-Phase Commit的缩写,即三阶段提交,是2PC的改进版,其二阶段提交协议的"提交事务请求"过程一分为二,形成了由CanCommit,PreCommit ...
- css工具类封装
温馨提示:一下css封装,建议按需使用,否则会造成很大的代码冗余,且很多样式会造成不符合预期的效果,建议合理使用 <a href="https://meyerweb.com/eric/ ...
- 转载 vi替换windows换行符为linux换行符
1.用vi打开指定文本文件:vi filename.c 2.按 Esc 键,进入命令模式: 3.按 : 键 (按 Shift 键不放后,同时按 : 键)进入命令输入状态: 4.在冒号后输入:%s/^M ...
- 利用ajax完成项目图册上传删除【实际项目】
[项目页面效果] [前台jsp页面] jsp的js代码 <script type="text/javascript"> //上传项目图片 function upload ...
- 应该抛出什么异常?不应该抛出什么异常?(.NET/C#)
我在 .NET/C# 建议的异常处理原则 中描述了如何 catch 异常以及重新 throw.然而何时应该 throw 异常,以及应该 throw 什么异常呢? 究竟是谁错了? 代码中从上到下从里到外 ...
- vector 介绍
介绍 这篇文章的目的是为了介绍std::vector,如何恰当地使用它们的成员函数等操作.本文中还讨论了条件函数和函数指针在迭代算法中使用,如在remove_if()和for_each()中的使用.通 ...
- mfc 鼠标、键盘响应事件
一.基本目标 1.有一个基本的MFC程序,点击“关闭”则“关闭”这个程序,这点没什么好讲的,把自带的“取消”按钮,右键->属性的Caption改成“关闭”二字就可以了 2.鼠标在对话框中移动,则 ...
- atom的设置
1.隐藏Keybinding Resolver Packages->Keybinding Resolver->Toggle.
- jQuery 异步和同步请求
在jQuery Ajax里面有一个async 参数 , 默认值 为true , 请求为异步请求 , false 为同步请求 .. 使用ajax加载数据返回页面并赋值,然后前端取出该值 这其中涉及到代码 ...
- 使用 lego生成 Let's Encrypt 证书
1. 工具 https://github.com/xenolf/lego 2. 使用 命令生成新的 lego --email="foo@bar.com" --domains=& ...