UVa 10935 - Throwing cards away I
模拟队列操作。 注意当n == 1时第一行输出末尾没有空格。PE一次~~~
代码 :
import java.util.*;public class Main10935 {public static void main(String[] args) {Scanner scan = new Scanner(System.in);Queue<Integer> q = new LinkedList<Integer>();while(true) {int n = scan.nextInt();if(n == 0) break;for(int i=1; i<=n; i++) {q.offer(i);}System.out.print("Discarded cards:");int cnt = 0;while(true) {cnt ++;if(q.size() == 1) break;//q.poll();if(cnt == 1)System.out.print(" " + q.poll());elseSystem.out.print(", " + q.poll());q.offer(q.poll());}System.out.println();System.out.println("Remaining card: " + q.poll());}}}
UVa 10935 - Throwing cards away I相关推荐
- 10行代码AC——UVa 10940(Throwing cards away II 数学规律+约瑟夫环)
励志用尽量少的代码做高效表达 题目(提交)链接-->UVa-10940 问题分析 本题的时间要求是3s,但极限数据量为50W*50W,一般来说,3s的时间只能支持不到三千万次的运算,也就是说,即 ...
- 17行代码AC——习题5-3 卡片游戏(Throwing cards away I, UVa 10935,约瑟夫环)_解题报告
励志用少的代码做高效的表达 题目(提交)链接→UVa-10935 本题为水题,因此侧重点由解题转向优化. 解题思路: 解法一思路:用vector动态数组存储,可以方便的实现插入.删除等操作. 解法二思 ...
- 【Uva - 10935】 Throwing cards away I (既然是I,看来还有Ⅱ、Ⅲ、Ⅳ?)(站队问题队列问题)
题干: Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bot ...
- UVA 10935 卡片游戏
这个题虽然很简单,但是也蛮坑的,需要注意,当输入的n为1时是不会有被丢弃的卡片的.而且,这个题有一个小bug,就是当输入的n = 2时,被丢弃的卡片只有一张,所以正确的输出格式应该为应该把cards改 ...
- UVa 1586 Molar mass 分子量 题解
英文 Description An organic compound is any member of a large class of chemical compounds whose molecu ...
- 暑期集训1:C++STL 例2:UVA-10935
2018学校暑期集训第一天--C++与STL 例二 -- UVA - 10935 Throwing cards away I Given is an ordered deck of n cards ...
- π-Algorithmist分类题目(1)
原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(1) Sorting UVAL ...
- 紫书《算法竞赛入门经典》
紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...
- 算法竞赛入门经典(第2版)—第五章(C++与STL入门)
文章目录 零碎知识点整理 题目 10474 - Where is the Marble? 101 - The Blocks Problem 10815 - Andy's First Dictionar ...
最新文章
- 9.QT-标准对话框
- SNF快速开发平台MVC-高级查询组件
- IP地址规划和路由实验
- 实验三进程调度模拟程序
- 【数字信号处理】相关函数应用 ( 相关函数应用场景 | 噪声中检测信号原理 )
- DELETE大批量数据的性能优化
- 手机桌面隐藏大师_应用加密,教你一招隐藏手机桌面上的软件!
- matlab 定义一个有自变量的方程_常微分方程:(第四章) 高阶微分方程
- 使用UIWebView加载网页
- 分别用 数组和链表处理约瑟夫环问题
- 1024节日快乐~~~~
- 实验二:编写输出Hello World!
- jqGrid获取一行数据的方法
- 手机链接路由wifi,设置为固定IP方法
- 数据库服务器修改地址,数据库服务器修改地址吗
- Ceres配置(vs2013+Win10)
- redis延时双删保证和数据库的一致性
- php权限无需验证的控制器,Thinkphp6用中间件实现多个控制器判断用户登录权限
- 对视频马赛克的调研学习报告
- 美团点评运营数据产品化实战