Acm hdu 1014 uniform Generator

Source: Internet
Author: User
Uniform Generator

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 6215 accepted submission (s): 2477

Problem descriptioncomputer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form

Seed (x + 1) = [seed (x) + step] % mod

Where '%' is the modulus operator.

Such a function will generate pseudo-random numbers (SEED) between 0 and mod-1. one problem with functions of this form is that they will always generate the same pattern over and over. in order to minimize this effect, selecting the step and mod values carefully can result in a uniform distribution of all values between (and including) 0 and mod-1.

For example, if step = 3 and mod = 5, the function will generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. in this example, all of the numbers between and including 0 and mod-1 will be generated every mod iterations of the function. note that by the nature of the function to generate the same seed (x + 1) every time seed (X) occurs means that if a function will generate all the numbers between 0 and mod-1, it will generate pseudo-random numbers uniformly with every mod iterations.

If step = 15 and mod = 20, the function generates the series 0, 15, 10, 5 (or any other repeating series if the initial seed is other than 0 ). this is a poor selection of step and mod because no initial seed will generate all of the numbers from 0 and mod-1.

Your program will determine if choices of step and MOD will generate a uniform distribution of pseudo-random numbers.

Inputeach line of input will contain a pair of integers for step and mod in that order (1 <= step, MOD <= 100000 ).

Outputfor each line of input, your program shocould print the step value right-justified in columns 1 through 10, the MOD value right-justified in columns 11 through 20 and either "Good choice" or "bad choice" left-justified starting in column 25. the "good choice" message shocould be printed when the selection of step and MOD will generate all the numbers between and including 0 and mod-1 when mod numbers are generated. otherwise, your program shocould print the message "bad choice ". after each output test set, your program shocould print exactly one blank line.

Sample input3 5
15 20
63923 99999

Sample output3 5 good choice

15 20 bad choice

63923 99999 good choice

Sourcesouth central USA 1996

Recommendjgshining
 
# Include <stdio. h> # include <iostream> # include <string. h> using namespace STD; int f [100000]; int main () {int step, MOD; int I, A; bool CNT; while (scanf ("% d", & step, & mod )! = EOF) {memset (F, 0, sizeof (f); CNT = true; a = 0; F [a] ++; for (I = 1; I <MOD; I ++) {A = (a + step) % MOD; F [a] ++; If (F [a]> = 2) {CNT = false; break ;}} printf ("% 10d % 10d", step, MoD); If (CNT) printf ("Good choice \ n "); else printf ("bad choice \ n");} return 0 ;}

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.