【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

用STL的queue写

【代码】

#include <bits/stdc++.h>
using namespace std; queue <int> dl;
vector <int> v;
int n; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
while (~scanf("%d", &n) && n)
{
v.clear();
while (!dl.empty()) dl.pop(); for (int i = 1; i <= n; i++) dl.push(i);
for (int i = 1; i <= n - 1; i++)
{
v.push_back(dl.front());
dl.pop();
dl.push(dl.front());
dl.pop();
}
printf("Discarded cards:");
for (int i = 0; i < n - 1; i++)
{
printf(" %d%c", v[i], i == n - 2 ? '\n' : ',');
}
if (n == 1) puts("");
printf("Remaining card: %d\n", dl.front());
}
return 0;
}

【习题5-3 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 I【队列】

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

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

  5. 【UVA】10935 Throwing cards away I(STL队列)

    题目 题目     分析 练习STL     代码 #include <bits/stdc++.h> using namespace std; int main() { int n; wh ...

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

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

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

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

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

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

随机推荐

  1. Linux下使用网上银行

    Linux下使用网上银行 650) this.width=650;" onclick="window.open("http://blog.51cto.com/viewpi ...

  2. nginx最新配置

    #user  nobody;worker_processes  1; #error_log  logs/error.log;#error_log  logs/error.log  notice;#er ...

  3. JavaScript--数据结构与算法之散列

    散列:实现散列表的数据后可以快速地实现插入或者删除.但是对于实现查找操作则效率非常的低.散列表的底层是数组实现的,长度是预先设定,可以随时根据需求增加.所有的元素根据和该元素对应的键,保存在特定的位置 ...

  4. logback 生成日志

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <appender ...

  5. 推断字符串string是数字、json结构、xml结构

    import org.json.JSONException; import org.json.JSONObject; import org.dom4j.DocumentException; impor ...

  6. sql简单的语句

    选择:select * from table1 where 范围 插入:insert into table1(field1,field2) values(value1,value2) 删除:delet ...

  7. SQlite-数据库的访问实例(转)

    1.DBAdapter类: 1 package com.cnzcom.android.quickdial; import android.content.ContentValues; import a ...

  8. Linux下搭建JSP环境

    Linux下搭建JSP环境     作为一名Java EE系统架构工程师,经常需要搭配和建立JSP(Java Server Pages)的开发环境和运行环境,所以本人在平时的工作中积累了一些在Linu ...

  9. Loadrunner经典测试实例

    Loadrunner经典测试实例

  10. 异步调用WCF的方法需要小心的地方

    直接使用下面的代码,由于client对象占用的资源没有被释放,会导致内存泄露GetSimServiceReference.GetSimServiceClient client = new GetSim ...