1704 card Games
time limit : 1 s
Space Limit : 128000 KB
title level : Silver
Title Description Description
There is a stack of cards on the table, starting from the first card (that is, the card at the top) and numbered 1~n from top to bottom. When there are at least two rows left to do: Throw away the first card and put the new first card at the end of the stack. Enter N. Output each time you discard the cards, and the last remaining cards.
Enter a description input Description
Input n
outputs description output Description
Output each time you discard the card, and the last remaining cards
sample input to sample
7
Sample output Sample outputs
1 3 5 7 4 2 6
Originally in the picture thesis, did not expect to jump out of this come, hehe
Water problem, a queue can be done.
#include <iostream>#include<queue>#include<cstdio>using namespacestd;intn,t,num=0; queue<int>A;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch>'9'|| ch<'0'){if(ch=='-') f=-1; ch=GetChar ();} while(ch<='9'&&ch>='0') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intMain () {n=read (); for(intI=1; i<=n;i++) A.push (i); while(num<n-1) {printf ("%d", A.front ()); A.pop (); T=A.front (); A.pop (); A.push (t); Num++; } printf ("%d\n", A.front ()); return 0;}
Code
1704 card Games