题干:

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

解题报告:

没事水一发还是很好的。。。但是这个输出格式有点坑啊。。1的时候,还不能带空格。

AC代码:

#include<bits/stdc++.h>using namespace std;int main()
{int n;while(~scanf("%d",&n)) {if(n == 0) break;else if(n == 1) {printf("Discarded cards:\n");printf("Remaining card: 1\n");continue;}queue<int > q;int flag = 0;for(int i =1 ; i<=n; i++) q.push(i);printf("Discarded cards: ");while(q.size()>1) {if(flag == 0) {printf("%d",q.front());q.pop();if(q.size() == 1) continue;q.push( q.front() );q.pop();flag = 1;continue;}printf(", %d",q.front());q.pop();if(q.size() == 1) continue;q.push( q.front() );q.pop();}printf("\nRemaining card: %d\n",q.front());q.pop();}return 0 ;
}

【Uva - 10935】 Throwing cards away I (既然是I,看来还有Ⅱ、Ⅲ、Ⅳ?)(站队问题队列问题)相关推荐

  1. UVa 10935 - Throwing cards away I

    模拟队列操作.  注意当n == 1时第一行输出末尾没有空格.PE一次~~~ 代码  : import java.util.*;public class Main10935 {public stati ...

  2. 10行代码AC——UVa 10940(Throwing cards away II 数学规律+约瑟夫环)

    励志用尽量少的代码做高效表达 题目(提交)链接-->UVa-10940 问题分析 本题的时间要求是3s,但极限数据量为50W*50W,一般来说,3s的时间只能支持不到三千万次的运算,也就是说,即 ...

  3. 17行代码AC——习题5-3 卡片游戏(Throwing cards away I, UVa 10935,约瑟夫环)_解题报告

    励志用少的代码做高效的表达 题目(提交)链接→UVa-10935 本题为水题,因此侧重点由解题转向优化. 解题思路: 解法一思路:用vector动态数组存储,可以方便的实现插入.删除等操作. 解法二思 ...

  4. UVA 10935 卡片游戏

    这个题虽然很简单,但是也蛮坑的,需要注意,当输入的n为1时是不会有被丢弃的卡片的.而且,这个题有一个小bug,就是当输入的n = 2时,被丢弃的卡片只有一张,所以正确的输出格式应该为应该把cards改 ...

  5. UVa 1586 Molar mass 分子量 题解

    英文 Description An organic compound is any member of a large class of chemical compounds whose molecu ...

  6. 暑期集训1:C++STL 例2:UVA-10935

    2018学校暑期集训第一天--C++与STL 例二  --  UVA - 10935 Throwing cards away I Given is an ordered deck of n cards ...

  7. π-Algorithmist分类题目(1)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...

  8. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

  9. 算法竞赛入门经典(第2版)—第五章(C++与STL入门)

    文章目录 零碎知识点整理 题目 10474 - Where is the Marble? 101 - The Blocks Problem 10815 - Andy's First Dictionar ...

最新文章

  1. 面试官眼中的计算机水平,面试官最不喜欢的五句话,千万别说了
  2. 多线程:线程同步的几种方式
  3. CentOS设置程序开机自启动的方法
  4. boost::contract模块没有宏实现base types的测试程序
  5. java 二阶段提交,二阶段提交协议(Two Phase Commitment Protocol)
  6. Python-关于正则表达式的总结
  7. Linux下安装Kafka(单机版)
  8. 定理在数学中的简写形式_湘教版八年级数学上册知识点总结
  9. c#动态编译并执行字符串
  10. Python爬虫基本原理
  11. JavaScript实现监听移动端上下左右滑动事件
  12. 论文翻译 SLAM综述
  13. 2021年下种子磁力最好用的网盘
  14. 15K服务器硬盘对齐分数,第七代15000RPM硬盘 希捷捷豹15K.7评测
  15. 【011】基于51单片机的低频信号发生proteus仿真与实物设计
  16. HTML CSS 模仿当当网
  17. Jqgrid+Struts2实现的增删改查(一)
  18. centos 安装 redis
  19. iOS 第三方dSYM定位BUG
  20. C++之string

热门文章

  1. [剑指offer]面试题第[56-2]题[JAVA][数组中数字出现的次数][状态机][hashmap][位运算]
  2. 1668智能下数教程视频_你需要的教程合集更新
  3. 运行时异常与一般异常有何异同_Java修行第015天,异常机制和常用类
  4. html读取本地txt_手机本地电子书籍阅读器 — 静读天下
  5. 图片自动翻转css代码,用css实现图片翻转(示例代码)
  6. excel排名_Excel案例:比赛中,如何实时显示排名
  7. 中职计算机说课稿三篇,精选中职计算机说课稿三篇-20210609060707.docx-原创力文档...
  8. installshield 指定多个自定义路径和文件
  9. win7下ffmpeg编译动态链接库整理
  10. HTTP代理原理以及HTTP隧道技术