原题 Throwing cards away I   Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck:   Throw away the top card and mo…
题目意思:有N张牌,标号为1~N,且牌以叠好,从上到小就是标号1-N的牌,只要牌堆数量大于等于2的时候,就采取如下操作:将最上面的牌扔掉(即离开牌堆).刚才那张牌离开后,再将新的最上面的牌放置于牌堆最后一张. 要求输出:依次输出被扔掉的牌,按扔掉的顺序输出.最后要输出最后留下的一张牌. 思路:用一个队列来模拟,被扔掉的牌相当于取出后进行pop操作,把最上面的牌放置最后相同于取出后进行pop操作和push操作,直至队列的size小于等于1 注意点:因为题目对格式的要求,所以第一张被扔掉的牌格式处理…
题意:给出 n张牌,从上往下编号依次为1到n,当牌的数目至少还剩下2张时,把第一张牌扔掉,然后把新的一张牌放在牌堆的最底部,问最后剩下的那一张牌是哪一张牌. 模拟队列的操作------- #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<queue> using namespace st…
Given is an ordered deck of    n    cards numbered 1 to    n    with card 1 at the top and card    n    at the bottom. The following operation is performed as long as there are at least two cards in the deck: Throw away the top card and move the card…
题目 题目     分析 练习STL     代码 #include <bits/stdc++.h> using namespace std; int main() { int n; while(scanf("%d",&n) && n!=0) { queue<int> q; printf("Discarded cards:"); for(int i=1;i<=n;i++) q.push(i); while(q.s…
题意略: 先暴力打表发现规律 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 ans=4N=11 ans=6N=12 ans=8N=13 ans=10N=14 ans=12N=15 ans=14N=16 ans=16N=17 ans=2N=18 ans=4N=19 ans=6N=20 ans=8N=21 ans=10N=22 ans=12N=23 ans=14N=24 an…
Throwing cards away I   Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck:  Throw away the top card and move t…
题目: Problem B: Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: Throw away the top car…
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) //UVa10935 - Throwing cards away I #include<iostream> #include<queue> int N; int main() { //freopen("in.txt", "r", stdin); while (scanf("%d", &N) !=…
POJ 1511 Invitation Cards / UVA 721 Invitation Cards / SPOJ Invitation / UVAlive Invitation Cards / SCU 1132 Invitation Cards / ZOJ 2008 Invitation Cards / HDU 1535 (图论,最短路径) Description In the age of television, not many people attend theater perfor…