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

模拟队列的操作-------

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<vector>
  6. #include<queue>
  7. using namespace std;
  8.  
  9. queue<int>q;
  10.  
  11. int main()
  12. {
  13. int i,j,n,ans,a,b;
  14. while(scanf("%d",&n)!=EOF&&n)
  15. {
  16. while(!q.empty()) q.pop();
  17. for(i=;i<=n;i++)
  18. q.push(i);
  19. printf("Discarded cards:");
  20. while(q.size()!=)
  21. {
  22. b=q.front();q.pop();
  23. if(q.size()!=) printf(" %d,",b);
  24. else printf(" %d",b);
  25. a=q.front();q.pop();
  26. q.push(a);
  27. }
  28. printf("\n");
  29. printf("Remaining card: %d\n",q.front());
  30. }
  31. }

UVa 10935 Throwing cards away I【队列】的更多相关文章

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

    Given is an ordered deck of    n    cards numbered 1 to    n    with card 1 at the top and card    n ...

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

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

  9. 紫书第五章训练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 ...

随机推荐

  1. c# 与flash通信简介

    许久不曾写随笔,即使许久的怠惰,是该抬抬头,看看天了. 公司项目,项目要求是在winForm端先获取下位机的肌电信号采集数据,然后根据这些数据的变化来控制flash游戏,这样一些患者在flash游戏中 ...

  2. F.I.S本地环境的搭建教程

    一.准备开发环境: 1.安装JRE 2.安装nodejs 最好是msi文件,比较省事. 3.(如果是PHP项目)安装php. 首先下载php(我的是5.5.15版本,win7 64位系统) zip,然 ...

  3. java 如何从配置文件(.properties)中读取内容

    1.如何创建.properties文件 很简单,建立一个txt文件,并把后缀改成.properties即可 2.将.properties文件拷入src的根目录下 3..properties文件内容格式 ...

  4. 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage”

    VS2012启动/加载项目出问题 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage, Microsoft.Visual ...

  5. WinDbg调试流程的学习及对TP反调试的探索

    基础知识推荐阅读<软件调试>的第十八章 内核调试引擎 我在里直接总结一下内核调试引擎的几个关键标志位,也是TP进行反调试检测的关键位. KdPitchDebugger : Boolean ...

  6. Jmeter 快速入门教程(三-3) -- 使用参数化

    参数化:简单的来理解一下,我们录制了一个脚本,这个脚本中有登录操作,需要输入用户名和密码,假如系统不允许相同的用户名和密码同时登录,或者想更好的模拟多个用户来登录系统. 这个时候就需要对用户名和密码进 ...

  7. sql主键的一点重要理解

    sql只会读取数据,不会自动设置主键,所以绑定数据后要设置主键(前台) 不管是int或者uniqueidentifier只要类型对得上就可以用,int自增其实没什么太大优势(但是通常都会用自增来做,从 ...

  8. lintcode:玩具工厂

    题目 工厂模式是一种常见的设计模式.请实现一个玩具工厂 ToyFactory 用来产生不同的玩具类.可以假设只有猫和狗两种玩具.   样例 ToyFactory tf = ToyFactory(); ...

  9. iOS 开发--Objective-C 反射机制

    了解反射机制 Objective-C语言中的OC对象,都继承自NSObject类.这个类为我们提供了一些基础的方法和协议,我们可以直接调用从这个类继承过来方法.当然,本篇文章中讲到的反射方法,就在NS ...

  10. 转载网易博客:整理各大网站让网站变灰的css代码

    2013-07-21 15:06:47 北京时间2013年4月20日8时02分四川省雅安市芦山县(北纬30.3,东经103.0)发生7.0级地震.震源深度13公里.各大网站将其网站变灰,本人整理了下部 ...