UVA-10935
来源:互联网 发布:dw软件破解版 编辑:程序博客网 时间:2024/06/03 18:05
从最上层取一张一处牌堆,再从最上层取一张放置到最底层
直到牌堆只剩一张牌为止。
输出移除卡牌的顺序和最后保留的卡片
解题思路:队列
WA点:当n=1时没有移除卡牌
代码:
#include <iostream>#include <queue>#include <cstdio>using namespace std;int main(){ int t,n; queue<int> q; while(scanf("%d",&n)&&n) { printf("Discarded cards:"); for(int i=1;i<=n;i++) { q.push(i); } if(n==1)puts(""); else while(1) { t=q.front(); q.pop(); if(q.size()==1) { printf(" %d\n",t); break; } else printf(" %d,",t); t=q.front(); q.pop(); q.push(t); } printf("Remaining card: %d\n",q.front()); q.pop(); } return 0;}
0 0
- UVa 10935
- UVA-10935
- uva 10935
- UVA 10935
- UVA 10935
- UVa 10935
- UVA 10935
- UVA 10935
- UVA 10935 约瑟夫环
- UVa 10935 卡片游戏
- UVa 10935 卡片游戏
- UVa 10935-卡片游戏
- UVA 10935 卡片游戏
- UVa 10935 queue教学
- uva 10935 卡片游戏
- UVa 10935 解题报告
- uva
- UVA
- 栈的链式存储结构及其基本运算的实现
- Share your java project to GitHub by EGit
- HDU 4915 Parenthese sequence
- hdu 1233 还是畅通工程
- JavaScript笔记-js基础
- UVA-10935
- unix shell 编程指南第九章 awk
- 继承,初始化方法
- man/help/info/doc
- Mybatis整合Spring
- hdu 1236 排名
- 静态常量和静态方法
- Android-视图显示大量图片时的内存问题_待更新
- spark集群管理简述