1704 card Games

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.