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 ...
随机推荐
- php正则验证手机号码
protected function checkphone(){ if(preg_match("/^1[34578]\d{9}$/", $phone)){ return false ...
- js实现IE/Firefox的收藏功能
代码: function addFavorite(el){ var url = window.location.href, title = $('head').find('title').html() ...
- Quartz.net Cron表达式
由7段构成:秒 分 时 日 月 星期 年(可选)"-" :表示范围 MON-WED表示星期一到星期三"," :表示列举 MON,WEB表示星期一和星期三&qu ...
- 安卓开发中ScrollView不能用RelativeLayout的解决方案
RelativeLayout的意义: 布局各个部件的相对布局.使得界面空间合理利用. 一.ScrollView局限: 滑动的只能是linearlayout,甚至整个布局都不能有RelativeLayo ...
- 屌炸天实战 MySQL 系列教程(二) 史上最屌、你不知道的数据库操作
此篇写MySQL中最基础,也是最重要的操作! 第一篇:屌炸天实战 MySQL 系列教程(一) 生产标准线上环境安装配置案例及棘手问题解决 第二篇:屌炸天实战 MySQL 系列教程(二) 史上最屌.你不 ...
- Java学习系列(一)Java的运行机制、JDK的安装配置及常用命令详解
俗话说:“十五的月亮十六圆”.那学习是不是也是如此呢?如果把月亮看成是我们的愿望,那十五便是我们所处的“高原期”,坚持迈过这个坎,我相信你的愿望终究会现实的.记得马云曾说:今天很残酷,明天更残酷,后天 ...
- 2015第14周五Tomcat版本
首先看tomcat官方文档,列出的不同版本的主要差别: Servlet Spec JSP Spec EL Spec WebSocket Spec Apache Tomcat version Actua ...
- PhpForm表单验证
<!DOCTYPE HTML> <html> <meta http-equiv="Content-Type" content="text/h ...
- poj 2229 Sumsets DP
题意:给定一个整数N (1<= N <= 1000000),求出以 N为和 的式子有多少个,式子中的加数只能有2的幂次方组成 如5 : 1+1+1+1+1.1+1+1+2.1+2+2.1+ ...
- JAVA中的Formatter
package com.st.day20150525; import java.util.Formatter; public class StringTest02 { /** * %[argument ...