Swjtu 2213 A Game about Cards (simulation questions)

Source: Internet
Author: User

title link : http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=2213

Thinking Analysis : This problem is similar to Joseph's problem; each time the top n cards are placed at the end of the queue, the entire queue can be treated as a ring, each moving forward n, then the number of the next card is numbered N.

and remove the card in the ring, continue n+1 step, so loop until the last card is numbered.

The code is as follows:

#include <iostream>using namespacestd;Const intMax_n = -;intDel[max_n];intNum[max_n];intMain () {intTimes ; CIN>>Times ;  while(times--)    {        intn =0; intindex =-1; Memset (Del,0,sizeof(del)); memset (num,-1,sizeof(num));
Cin>>N;  for(inti =0; I < n; ++i) {intTimes = i +1; intGo =Times ;  while(GO) {index= (Index +1) %N; if(Del[index]! =1) Go--; } Index= (Index +1) %N;  while(Del[index] = =1) Index= (Index +1) %N; Num[index]=Times ; Del[index]=1; }         for(inti =0; I < n-1; ++i) cout<< Num[i] <<" "; cout<< Num[n-1] <<Endl; }    return 0;}

Swjtu 2213 A Game about Cards (simulation questions)

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.