Uniform Generator

Problem Description
Computer 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.

Input
Each line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).

Output
For each line of input, your program should 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 should 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 should print the message "Bad Choice". After each output test set, your program should print exactly one blank line.

Sample Input
3 5
15 20
63923 99999

Sample Output
3 5 Good Choice

    15        20    Bad Choice

 63923     99999    Good Choice

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
HDU 1014:Uniform Generator【模拟】
Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24185    Accepted Submission(s): 9576 Problem Description Compute
HDU 1014 Uniform Generator 题解
找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易。 本题就是求step和mod如果GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choice 为什么这个结论成立呢? 因为当GCD(step, mod) == 1的时候,那么第一次得到序列:x0, x0 + step, x0 + step…… 那么mod之后,必然下一次重复出现比x0大的数必
HDU1014 Uniform Generator
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1014这道题就是题目有点难懂,其实难度很小,就是产生伪随机数时给出的步长step和上限mod,判断下这两个值是否可以让产生的随机数均匀分布,所谓的均匀分布就是在mod步里能产生出0到mod-1这mod个数。Code highlighting produced by Act
Uniform Generator
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29821#problem/E // File Name: bo_jwolf5.cpp // Author: rudolf // Created Time: 2013年08月21日 星期三 16:49:46 #include #include #include #include #inc
UVa 408 - Uniform Generator
UVa 408 - Uniform Generator
HDU—— 1014 Uniform Generator
题意:duiy公式:seed(x+1) = [seed(x) + STEP] % MOD,
HDOJ 1014 Uniform Generator
【题意】计算机模拟都需要随机数。一个产生伪随机数的方法是通过一个  seed(x+1) = [seed(x) + STEP] % MOD  这样形式的方法。如果不用STEP的话,将产生很有规律的随机数从0-mod-1,这样不好。如果加上STEP,例如 STEP = 3 and MOD = 5,则产生0, 3, 1, 4, 2,称为uniform distribution(均匀分布)。如果是STEP
HDOJ-1014 Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16203    Accepted Submission(s): 6336 Problem Description Compute
uva-408 - Uniform Generator
这道题目就是给你两个数,让你看看他们之间的最大公约数是不是1,用辗转相除法或者辗转相减法做。。 还有就是注意的一点,不要忘记每一个案例之后都有一个空行/。。。 #include int main() { int a,b,m,n,t; while(scanf("%d%d",&m,&n)!=EOF) { a=m,b=n; while(a) { t=a; a=b
uva_408 - Uniform Generator
Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form where ``  " is the modulus operator. Such a function will generate ps
UVA - 408 Uniform Generator
Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form where `` " is the modulus operator. Such a function will generate ps
poj 1597 Uniform Generator
Uniform Generator Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5035   Accepted: 2376 Description Computer simulations often require random numbers. One way
408 - Uniform Generator
题目:408 - Uniform Generator 题目大意:就是给你一个增量a和模数b,问你这个数能根据上面给的公式产生0 ~b-1的数吗? 解题思路:就是问给出的a 和 b 除1以外还有公因子吗?有的话不能产生上述的数。没有就可以。因为一旦有公因数, 从0开始加a,因为有公因子n(n> 1),这样的话,a* n == b,说明从0 开始总会到b,这样在模b,余数就又是0.
HDU 1014 — Uniform Generator
原题:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题意: 给出step, mod,然后根据公式产生随机数,初始数字都为0; 若在0到mod-1的范围内,每个数都只出现一次,则输出good choice,否则输出bad choice; 思路: 将产生的随机数都放到一个数组里,对数组进行排序,然后判断是否有出现相同的数字; 注意格式
Uniform Generator hdu-1014
题目来源:hdu-1014 Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22038 Accepted Submission(s): 8671 Problem Descriptio
HUD 1014 Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22663    Accepted Submission(s): 8903 Problem Description Computer si
【HDU】 1014 Uniform Generator
Uniform Generator 题目链接 Uniform Generator题目大意 题目中给了一个计算机做随机数的公式,现在公式中有两个数a,b,现在给你这两个数a,b,问用这两个数能取得0~b-1的随机数吗。题解 这个题就是直接求就好…..但是网上有人说只需要判断gcd(a,b)是否等于1…关于这个求法还不是很懂,自己推也没有推出来,等以后积累多了再回头来看吧。代码 #include
1154: Uniform Generator
<br />1154: Uniform GeneratorResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE3s8192K755282StandardComputer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form <br />seed(x+1) = [seed(x) + STE
HDU:1014 Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 27887    Accepted Submission(s): 11088 题目链接 Problem Description Co
poj1597 Uniform Generator
1、欧几里德定理(即辗转相除法) 2、中国剩余定理 3、维基百科中 “数学上的应用”这一块应该再加研究。
HDU1014 ( Uniform Generator )
Problem : 1014 ( Uniform Generator ) Judge Status : Accepted RunId : 5542633 Language : C++ Author : ssun Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta #include #i
HDU1014 Uniform Generator(模拟)
Uniform GeneratorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29850 Accepted Submission(s): 11889Problem Description Computer simulation
HDU1014 Uniform Generator (数论)
HDU1014 Uniform Generator (数论) HDU1014 Uniform Generator (数论) 题意 思路 AC代码 原题地址: 题意 给出STEP和MOD的值,问能否通过给出的式子得到1到mod-1的全部数。 思路 其实只需要判断两个数是否互质就可以了,判断互质只需要使用辗转相除法判断最大公约数是否为1即可。 辗转相除法: 用较...
UVa 408: Uniform Generator
这道题要求判断STEP和MOD的值是"Good Choice"还是"Bad Choice"。 观察分析后可以发现step和mod互质时是Good Choice,否则为Bad Choice。下面证明: 我们可以这样分析: 因为 所以 每次产生的seed只与上一个seed,STEP, MOD有关。当STEP, MOD的值确定时,假定第一个seed的值为0,则所得的seed序列是确定的。 该序
HDU ACM1014——Uniform Generator
Uniform Generator Problem Description Computer 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...
Uniform Generator hdu 1014
Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13919    Accepted Submission(s): 5457 Problem Description Computer si
HDU 1014 Uniform Generator
http://acm.hdu.edu.cn/showproblem.php?pid=1014 没事做,刷一些水题或基础题: #include #include #include #define DM 10 using namespace std; int Step = 0, Mod = 0; /*intialize the var*/ int InitVar() {
Hdoj 1014 Uniform Generator
题目:点击打开链接 分析:题目要求均匀产生随机数,有两种方法:1 对产生的数进行标记 2 要产生随机数STEP和MOD的最大公约数不能超过1 代码一: #include #include int a1[100010]; int main() { int STEP,MOD; while(~scanf("%d%d",&STEP,&MOD)) { int i; in
uva 408 Uniform Generator
求最大公约数. #include #include #include #include using namespace std; int gcd(int a,int b) { if(b==0)return a; return gcd(b,a%b); } int main() { int a,b; while(cin>>a>>b) { co
uva 408 - Uniform Generator
永远也别轻易相信测试数据找到的规律   他们只会坑死你  一切都应该从问题本身入手
Uniform Generator 数学题
/*这种题写过两次。第一次周赛的第一道就是他。就是给两个数,a,b.amodb的结果,再mod b,如果所有的余数能把0--mod-1内的所有数都填满。 则符合条件。这样只需要判断a b 互质即可。*/ #include int gcd(int a,int b) { return b==0?a:gcd(b,a%b); } int main() { int a,b; whi
【HDOJ】【1014】Uniform Generator
前后提交了6次,才AC。这些提示都是Presentation Error,说明是格式的错误。 题目中的第三个测试用例,最初的代码总是判断出错,原因是迭代值已经超过int型的最大数,所以将类型改为__int64。 另外,此题的输出中,每个用例的输出之间有一个空行,所以加了一个\n,问题解决。 #include #include #include /* run this program
杭电1014 ——Uniform Generator
刚看题目,对于英语不好的人来说有点头疼,不过忽略不必要的题干就会发现是道水题,题意很简单,多次输入,一次两个数,求其最大公约数,若为1输出"Good......",否则输出“Bad......”。唯一要注意的就是输出格式,题目要求每次两个数输入的两个数均要右对齐,且第一个数在1到10位,第二个数在11到20位,输出的判段(Good.....,Bad.....)左对齐,在5位输出。#include
UVA-408 Uniform Generator
2016-08-12 UVA - 408 Uniform Generator 题目大意:给出 step 和 mod,根据 seed(x+1)=[seed(x)+step]%10mod,问产生的随机数是否均匀分布于 0 到 mod-1。 解题思路:判断2个数是不是互质,用辗转相除法就好了。 #include #include using namespace std
杭电1014 Uniform Generator
/********************************  *    日期:2011-2-7  *    作者:SJF  *    题号:杭电1014  *  题目:Uniform Generator  *    结果:AC  ********************************/ #include int main() {     long int S
UVa408 Uniform Generator
其实就是求俩数是否互质。辗转相除法。#include #include using namespace std; int gcd(int a,int b) { int r = a % b; if (r == 0) return b; else { a = b; b = r; gcd(a,b); } } int main() { int a; int b; int
HDU1014:Uniform Generator
Problem Description Computer 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 th
【HDOJ】1014 -> Uniform Generator
心得:         本题可转化为证明step与mod互质,因为若step与mod不互质,则seed[gcd(step,mod)]=0。 代码: #include using namespace std; int gcd(int a,int b){ if(!b) return a; return gcd(b,a%b); } int main() {
UVA Uniform Generator
Uniform Generator  Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form where ``  " is the modulus ope
HDU 1014 Uniform Generator
Problem Description Computer 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
相关热词 c#sdf数据库连接 c# 使用配置文件 c#float 转int c#报警指示灯 c#复制二维数组 c# 歌词滚动 c#获取数据库一列数据 c#中parse用法 c#异步编程是什么意思 c#验证手机号正则