UVa 10935 Throwing cards away I【队列】
题意:给出 n张牌,从上往下编号依次为1到n,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌。
模拟队列的操作-------
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std; queue<int>q; int main()
{
int i,j,n,ans,a,b;
while(scanf("%d",&n)!=EOF&&n)
{
while(!q.empty()) q.pop();
for(i=;i<=n;i++)
q.push(i);
printf("Discarded cards:");
while(q.size()!=)
{
b=q.front();q.pop();
if(q.size()!=) printf(" %d,",b);
else printf(" %d",b);
a=q.front();q.pop();
q.push(a);
}
printf("\n");
printf("Remaining card: %d\n",q.front());
}
}
UVa 10935 Throwing cards away I【队列】的更多相关文章
- 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 <queue>
Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n ...
- 【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 ...
- 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 ...
- [刷题]算法竞赛入门经典(第2版) 5-3/UVa10935 - Throwing cards away I
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #incl ...
- 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 ...
- 紫书第五章训练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 ...
随机推荐
- js弹出图片原图效果
1.将js方法独立出来common.js function openwin(src){ var basePath = document.getElementById("basePath&qu ...
- GA项目体会
1.NaN表示运算的结果是未定义的计算过程,例如0/0.在计算EBO的时候,由于使用泊松分布的计算过程,出现了0/0的情况,所以控制台才会提示"非数字". 2.保障资金太小的时候可 ...
- javascript笔记 面向对象
Javascript是一种面向对象的弱语言,既然有面向对象,就有继承 继承: 1.call函数和apply函数:区别在于它们参数上的不同,固定参数的用call,可变参数的用apply.换句话说,就是a ...
- HDU 4148 Length of S(n)(字符串)
题目 字符串处理 题意要猜,解析见代码: /* 这题每个S(n)是描述S(n-1)值 例如: S(1)=1; S(2)=11;即描述S(1)有1个1=11 S(3)=21;即描述S(2)有2个1=21 ...
- OneApm,NewRelic
https://newrelic.com/ http://www.csdn.net/article/2013-03-25/2814631-new-relic-mobile-app-real-time- ...
- poj 2425 A Chess Game 博弈论
思路:SG函数应用!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include< ...
- Understanding node.js
Node.js has generally caused two reactions in people I've introduced it to. Basically people either ...
- hdu1715
http://acm.hdu.edu.cn/showproblem.php?pid=1715 模板大数: #include <stdio.h> #include <string.h& ...
- java开发--反射技术
学习目标: 1.什么是反射:即反射的定义, 2.反射有什么作用,能解决什么问题, 3.反射的知识点是什么, 4.反射的利弊 5.反射的例子 1.什么是反射:反射的定义: a) 能够分析类能力的程序被称 ...
- Java-马士兵设计模式学习笔记-责任链模式-处理数据
一.目标 数据提交前做各种处理 二.代码 1.MsgProcessor.java public class MsgProcessor { private List<Filter> filt ...