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.

Input

  Each line of input (except the last) contains a number n≤ 50. The last line contains ‘0’ and this line should not be processed.

Output

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

Sample Output

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
Discarded cards:
Remaining card: 1

HINT

  简单的队列操作,需要注意的是当n=1时应该如何输出,第一行后面无空格,具体键上面样例输入。

Accepted

#include<iostream>
#include<queue>
using namespace std;
int main()
{
int n,t;
while (cin>>n&&n)
{
queue<int>game;
for (int i = 1;i <= n;i++)game.push(i);
cout << "Discarded cards:";
for (int i = 1;game.size() > 1;i++)
{
cout << " " << game.front();
game.pop();
game.push(game.front());
game.pop();
if (game.size() > 1)cout << ",";
}
cout << endl << "Remaining card: " << game.front() << endl;
}
}

Throwing cards away I UVA - 10935的更多相关文章

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

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

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

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

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

  6. 紫书第五章训练3 D - Throwing cards away I

    D - Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top ...

  7. UVA10940 - Throwing cards away II(找到规律)

    UVA10940 - Throwing cards away II(找规律) 题目链接 题目大意:桌上有n张牌,依照1-n的顺序从上到下,每次进行将第一张牌丢掉,然后把第二张放到这叠牌的最后.重复进行 ...

  8. Uva 10935 Throwing cards away I

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

  9. UVa 10935 (水题) Throwing cards away I

    直接用STL里的queue模拟即可. #include <cstdio> #include <queue> using namespace std; ; int discard ...

随机推荐

  1. Qt+opencv亲自配置教程

    了别人的配置,总是无法配置成功,自己慢慢摸索配置成功.我失败的原因是在于自己本机的环境变量和他们不同,特此记下,分享给有相同问题的朋友. 一.需要软件 1.cmake 3.11.3(版本无所谓) 2. ...

  2. Youcans 的第一篇博客

    这是我的第一篇博客. 今后我会将我的学习心得和总结在这里发布,与大家共享,共勉.

  3. go 报错 import cycle not allowed

    运行时报错,import cycle not allowed : 查了goole大概知道了原因,还是导包类的问题,我检察了一下我的代码库,发现我昨天划分几个工具文件,里面的两个文件相互引用,就导致报i ...

  4. Shiro反序列化漏洞检测、dnslog

    目录 信息收集 poc 参考 信息收集 poc # pip install pycrypto import sys import base64 import uuid from random impo ...

  5. python带颜色打印字符串

    python带颜色打印字符串 之前调试pwn题的时候,有时候需要将某些特别的,重要的信息用不一样的颜色打印出来.查阅一些资料,了解了print函数的特性后,自己写了一个脚本,可以用来获取带颜色信息的字 ...

  6. Linux下查看文件内容的几种常用命令

    [常用] 1,cat     由第一行开始显示内容,并将所有内容输出 cat的功能是将文件从第一行开始连续的将内容输出在屏幕上.但是cat并不常用,原因是当文件大,行数比较多时,屏幕无法全部容下时,只 ...

  7. This is my first blog----文件操作基本流程

    一,文件操作基本流程. 计算机系统分为: 计算机硬件, 操作系统, 应用程序三部分 我们用python或其他语言编写的应用程序若想要把数据永久保存下来,必须要保存于硬盘中,这就涉及到应用程序要操作硬件 ...

  8. POJ_1273 Drainage Ditches 【网络流】

    一.题面 Drainage Ditches 二.分析 网络流的裸题. 1 Edmonds-Karp算法 求解网络流其实就是一个不断找增广路,然后每次找到一条增广路后更新残余网络的一个过程. EK算法主 ...

  9. python网络编程TCP服务多客户端的服务端开发

    #服务多客户端TCP服务端开发 2 #方法说明 3 """ 4 bind(host,port)表示绑定端口号,host是ip地址,ip地址一般不进 行绑定,表示本机的任何 ...

  10. MUV LUV UNLIMITED Gym - 102361K

    题目链接:https://vjudge.net/problem/Gym-102361K 题意:两个人轮流取树叶,最后没有树叶取的人输. 思路:求出所有树叶所在链的长度即可,如果都为偶数先手必败,否则先 ...