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 at the bottom. The following operation is performed as long as there are at least two cards in the deck:
Throw away the top card and move the card that is now on the top of the deck to the bottom of the deck.
Your task is to find the sequence of discarded cards and the last, remaining card.
Each line of input (except the last) contains a number n ≤ 50. The last line contains 0 and this line should not be processed. For each number from the input produce two lines of output. The first line presents the sequence of discarded cards, the second line reports the last remaining card. No line will have leading or trailing spaces. See the sample for the expected format.
Sample input
7
19
10
6
0
Output for sample input
Discarded cards:1,3,5,7,4,2
Remaining card:6
Discarded cards:1,3,5,7,9,11,13,15,17,19,4,8,12,16,2,10,18,14
Remaining card:6
Discarded cards:1,3,5,7,9,2,6,10,8
Remaining card:4
Discarded cards:1,3,5,2,6
Remaining card:4 这道题超简单,五分钟一次写完运行成功
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std; queue<int> cards;
int main()
{
int n;
while( scanf( "%d", &n ) == ){
if(n == ) break;
for(int i = ;i <= n; i++)cards.push(i); printf("Discarded cards:");
int t;
for(int i = ;i < ; i++){
if(i == )cout << cards.front();
else cout << "," <<cards.front();
cards.pop();
t = cards.front();
cards.pop();
if(cards.empty())break;
cards.push(t);
}
printf("\nRemaining card:%d\n",t);
}
//system("pause");
return ;
}
uva 10935 throwing cards away <queue>的更多相关文章
- 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 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 / ...
- 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 ...
随机推荐
- pygame实现的黑白块游戏
运行时需要pygame库. 下载地址:http://files.cnblogs.com/files/zzrom/white.zip 程序截图:
- hadoop容灾能力测试
实验简单来讲就是 1. put 一个600M文件,分散3个replica x 9个block 共18个blocks到4个datanode 2. 我关掉了两个datanode,使得大部分的block只在 ...
- apache 出现Index of /的页面解决
在apache安装文件中找到http.conf配置文件,打开找到 Options Indexes FollowSymLinks 这行,在Indexes前加一个-(减号),也就是该完之后是这样: Opt ...
- CSS优先级、引入方式、Hack
优先级 important > 内联(1,0,0,0) > id(1,0,0) > class(1,0) > element(1) > *通配符 css引入方式 方式一: ...
- PHP命名空间(Namespace)的使用详解(转)
对于命名空间,官方文档已经说得很详细[查看],我在这里做了一下实践和总结. 命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会产生一个致命的错误.这种情况下只 ...
- 自定义View—坐标系
一.android默认坐标系 二.View 的 getXxx()的坐标系 三.event的坐标系
- 函数:我的地盘听我的 - 零基础入门学习Python019
函数:我的地盘听我的 让编程改变世界 Change the world by program 函数与过程 在小甲鱼另一个实践性超强的编程视频教学<零基础入门学习Delphi>中,我们谈到了 ...
- [C入门 - 游戏编程系列] 贪吃蛇篇(五) - 蛇实现
因为已经写了食物的实现,所以我不知道到底是该先写世界的实现还是蛇的实现.因为世界就是一个窗口,可以立刻在世界中看到食物的样子,对于大多数人来说,如果写完代码立刻就能看到效果,那就再好不过了.可是,我最 ...
- Java中的日期处理类
在Java中可以使用Date类和Calendar类来处理日期 但是Date类很多方法都过时了,推荐使用Canlendar类来处理日期,并对日期的格式化做了介绍.下面的部分将会逐一介绍 Date类 Ja ...
- (转)CentOS搭建Nagios监控
A.Nagios服务端1.安装软件包 yum install -y httpd 2.下载nagios wget http://syslab.comsenz.com/downloads/linux/na ...