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>的更多相关文章

  1. 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 ...

  2. Uva 10935 Throwing cards away I

    题目意思:有N张牌,标号为1~N,且牌以叠好,从上到小就是标号1-N的牌,只要牌堆数量大于等于2的时候,就采取如下操作:将最上面的牌扔掉(即离开牌堆).刚才那张牌离开后,再将新的最上面的牌放置于牌堆最 ...

  3. UVa 10935 Throwing cards away I【队列】

    题意:给出 n张牌,从上往下编号依次为1到n,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌. 模拟队列的操作------- #inclu ...

  4. 【UVA】10935 Throwing cards away I(STL队列)

    题目 题目     分析 练习STL     代码 #include <bits/stdc++.h> using namespace std; int main() { int n; wh ...

  5. 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 ...

  6. 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 ...

  7. [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...

  8. 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 / ...

  9. 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 ...

随机推荐

  1. UVA442 栈

    C - Matrix Chain Multiplication Crawling in process... Crawling failed Time Limit:3000MS     Memory ...

  2. DOM 之selection

    有关文章的集合 MOZILLA 开发者网络 selection: MOZILLA DEVELOPER NETWORK document.activeElement MOZILLA DEVELOPER ...

  3. 简单的thinkPHP3.2运行实例。

    在上一篇的环境基础下. 我们用zendstudio12.5版本编写我们的代码.具体的下载方式在这里就不多做注明了.自己百度就可以搞定. 首先我们用zendstudio12.5 导入我们从网上随处都可以 ...

  4. 微信小程序开发工具 常用快捷键

    格式调整 Ctrl+S:保存文件 Ctrl+[, Ctrl+]:代码行缩进 Ctrl+Shift+[, Ctrl+Shift+]:折叠打开代码块 Ctrl+C Ctrl+V:复制粘贴,如果没有选中任何 ...

  5. Java compiler level does not match the version of the installed Java project facet.解决办法

    问题原因: 出现这个问题的原因是因为,eclipse/myeclipse的jdk编译版本与出现问题的项目JDK编译版本不一致所导致!   解决办法: 工程名---->右键properties-- ...

  6. 开心菜鸟学习系列笔记-----Javascript(1)

    js 一些常见的使用方法        // target : 不管是否出现冒泡,他都是代表最开始引发事件的对象   // this   : 是指当前函数.  //ie 事件对象   : window ...

  7. Ext4.0.7使用Ext.grid.ColumnModel报错:TypeError: Ext.grid.Model is not a constructor

    代码如下: Ext.onReady(function(){ //定义列 var cm = new Ext.grid.ColumnModel([ {header: '编号', dataIndex: 'i ...

  8. 一键安装IIS的点点滴滴——For所有Microsoft的操作系统(上)

    原文www.cnblogs.com/cdts_change/archive/2010/03/04/1677338.html 临近公司的软件要完工了,最近几天一直在泉哥的带领下为我们公司的产品做IIS一 ...

  9. (\S)? 匹配0个或者一个前导字符

    ---------------------------------------------- "1" 模式: \"(?<id>(\S+)?)\" ? ...

  10. 【转】UltraISO制作U盘启动盘安装Win7/9/10系统攻略

    U盘安装好处就是不用使用笨拙的光盘,光盘还容易出现问题,无法读取的问题.U盘体积小,携带方便,随时都可以制作系统启动盘. U盘建议选择8G及以上大小的. 下面一步一步讲解如果制作U盘安装盘: 1.首先 ...