HDOJ 1014 Simulation

Source: Internet
Author: User

The main topic: give two number, s,m, according to the requirements of the question to calculate the generated random sequence, to determine whether 0~m-1 this M-series, if it is a good choice, otherwise is bad choice.

Algorithm idea;

Use a tag flag[maxn] to record the first 0~m-1 is generated, and NUM record the length of the sequence, the loop to determine whether the current number has been generated before, if there is no mark, no and determine whether NUM is equal to M, if the wait is a good choice, unequal is not a good choice. The output is 10 bytes in S,m, and the string starts out in 25 columns and is left-justified. Empty line after each use case.

The code is as follows:

#include <iostream> #include <iomanip> #include <cstring> #include <algorithm>using namespace Std;const int Maxn=111111;bool Flag[maxn];int main () {    int s,m;    int seed;    while (cin>>s>>m) {      int num=0;      memset (flag,0,sizeof (flag));      seed=0;      while (!flag[seed]) {           flag[seed]=true;         Seed= (seed+s)%m;         num++;        }      if (num==m) COUT<<RIGHT<<SETW (Ten) <<S<<SETW (Ten) <<m<< "    " <<left< < "good Choice" <<endl<<endl;      else COUT<<RIGHT<<SETW <<S<<SETW (Ten) <<m<< "    <<left<<" Bad Choice "<<endl<<endl;    }        return 0;}


HDOJ 1014 Simulation

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.