【习题5-3 UVA-10935】Throwing cards away I
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
用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的更多相关文章
- 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 <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 ...
- 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 / ...
随机推荐
- Python print 语句(Python 2 与 Python 3)
1. python 3.x 中的 print print 在 Python 3.x 的环境里是内置函数(built-in function): python 3 的 print 语句支持(python ...
- CSS盒子模型图
下面这张图,是W3C标准的CSS盒子模型: 由上图可以清楚的看出各个部分的CSS属性.
- 洛谷P3383 【模板】线性筛素数(Miller_Rabin)
题目描述 如题,给定一个范围N,你需要处理M个某数字是否为质数的询问(每个数字均在范围1-N内) 输入输出格式 输入格式: 第一行包含两个正整数N.M,分别表示查询的范围和查询的个数. 接下来M行每行 ...
- Exercise: PCA in 2D
Step 0: Load data The starter code contains code to load 45 2D data points. When plotted using the s ...
- Javascript和jquery事件--事件冒泡和事件捕获
jQuery 是一个 JavaScript 库,jQuery 极大地简化了 JavaScript 编程,在有关jq的描述中,jq是兼容现有的主流浏览器,比如谷歌.火狐,safari等(当然是指较新的版 ...
- 004 python 流程控制语句
流程控制语句 1.if判断 语法 a = 10,b = 20# 1if a == 10: print('a等于10')# 2if a > b: print('a大于b')else: pri ...
- Autodesk 招聘Revit二次开发咨询顾问,与Autodesk全球团队紧密合作,提高职业生涯的好机会
朋友们, 因为我离开Autodesk的全职工作(变为部分时间工作),我的职位空出.急招这个职位.请踊跃把你周围的朋友推荐给Autodesk. 请将简历发给我转交给Autodesk 我的邮箱yexion ...
- Centos6.4安装opennebula
Centos6.4安装opennebula #安装163源 http://mirrors.163.com/.help/CentOS6-Base-163.repo #安装epel源 wget http: ...
- jquery constructor(null)
<!-- jQuery = function() { --> <!-- return new jQuery.fn.F(); --> <!-- }, --> < ...
- Hp Open View安装使用视频
去年完成的cisco works 2000操作(http://chenguang.blog.51cto.com/blog/350944/124729)视频深受广大博友欢迎许多人来信咨询,最近刚做完一个 ...