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 ...
随机推荐
- photoshop基础
在Photoshop中,对图像的某个部分进行色彩调整,就必须有一个指定的过程.这个指定的过程称为选取.选取后形成选区. 现在先明确两个概念: 选区是封闭的区域,可以是任何形状,但一定是封闭的.不存在开 ...
- 用Stopwatch类获得程序运行时间
我们可以用Stopwatch类获得程序的运行时间,在优化代码时,可以用此方法来查看优化前后程序所耗费的时间 //Stopwatch类別在System.Diagnostics命名空间里 Stopwatc ...
- tomcat下context.xml中JNDI数据源配置
jndi(Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API.命名服务将名称和对象联系起来,使得我们可以用 ...
- 机器学习之逻辑回归(Logistic Regression)
1. Classification 这篇文章我们来讨论分类问题(classification problems),也就是说你想预测的变量 y 是一个离散的值.我们会使用逻辑回归算法来解决分类问题. 之 ...
- HDU5569/BestCoder Round #63 (div.2) C.matrix DP
matrix Problem Description Given a matrix with n rows and m columns ( n+m is an odd number ), at fir ...
- sql openxml sp_xml_preparedocument xml 中文乱码
DECLARE @xmlText xml ,@idoc int set @xmlText = (select doc from openrowset(bulk 'C:\Word\SRC\WebApp\ ...
- Project Euler 107:Minimal network 最小网络
Minimal network The following undirected network consists of seven vertices and twelve edges with a ...
- 欧拉工程第52题:Permuted multiples
题目链接 题目: 125874和它的二倍,251748, 包含着同样的数字,只是顺序不同. 找出最小的正整数x,使得 2x, 3x, 4x, 5x, 和6x都包含同样的数字. 这个题目相对比较简单 暴 ...
- hdu 4159 Indomie (DP,数学概率)
推出数学公式: #include<stdio.h> #include<string.h> __int64 C(int m,int n) { __int64 tmp=; if(m ...
- 将IDEA快捷键改为Eclipse模式
windows下选择File-->Settings,搜索Keymaps,右栏选择Eclipse