HDU 1014.Uniform Generator Problem Solving report

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1014

Topic meaning: Give STEP and mod, and then according to this formula: Seed (x+1) = [Seed (x) + STEP]% MOD, ask whether in a cycle can produce 0 ~ mod-1 number. Output "Good Choice" if possible, otherwise the output "bad Choice".

Long ago left the problem, previously thought the topic meaning long, thought is very difficult topic ... Today, see the "Short Code of the United States" to see this problem, simply did. Paper Tiger One!

You can initialize seed to 0, and then initialize i = 1 with a formula, because the initialized seed = 0 already occupies one time. The final judgment number is equal to MOD, is the word represents 0 ~ MOD-1 The number has appeared, output "Good Choice"

Finally, the format problem, STEP and MOD each occupy 10 columns, respectively, 1~10 and 11 ~ 20. String beginning in 25 columns, remember to output two blank lines after the answer!

  

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 using namespacestd;6 7 intMain ()8 {9     intstep, mod;Ten      while(SCANF ("%d%d", &step, &mod)! =EOF) One     { A         intD =0; -         inti =1; -          for(; d = (d+step)%mod; i++) the             ; -printf"%10d%10d%s\n\n", step, mod, i = = mod?"Good Choice":"Bad Choice"); -     } -     return 0; +}

"The beauty of the code," said can be used, linear with congruential to do seed (x+1) = [A*seed (x) + STEP]% MOD, this problem is A = 1. The final thing is to judge Coprime, but some do not understand very well, and feel the code written to the very rules, although shorter but less readable .....

HDU 1014.Uniform Generator Problem Solving report

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.