Uniform Generator

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32990    Accepted Submission(s): 13081

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

 
英语渣, 开始没看明白(囧), 后来师兄说只要两数互质就行:
 
#include<iostream>
#include<cstdio> using namespace std; int gcd(int a, int b)
{
return b == ? a: gcd(b, a % b);
}
int main()
{
int a, b;
while ( cin >> a >> b)
{
printf("%10d%10d ", a, b);
printf(gcd(a, b) == ? "Good Choice": "Bad Choice");
printf("\n\n");
}
}

所以最后也没看明白题目说什么T^T

 
 

HDU 1014 Uniform Generator(题解)的更多相关文章

  1. HDU 1014 Uniform Generator 题解

    找到规律之后本题就是水题了.只是找规律也不太easy的.证明这个规律成立更加不easy. 本题就是求step和mod假设GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choic ...

  2. HDU 1014 Uniform Generator(模拟和公式)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...

  3. HDU 1014 Uniform Generator【GCD,水】

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. HDU 1014:Uniform Generator

    Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. hdu 1014.Uniform Generator 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目意思:给出 STEP 和 MOD,然后根据这个公式:seed(x+1) = [seed(x) ...

  6. HDU 1014 Uniform Generator 欧几里得

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这 ...

  7. hdu 1014 Uniform Generator 数论

    摘取于http://blog.csdn.net/kenden23/article/details/37519883: 找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易. ...

  8. HDU 1014 Uniform Generator(最大公约数,周期循环)

    #include<iostream> #include <cstdio> #include <cstring> using namespace std; int m ...

  9. 1014 Uniform Generator ACM

    http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目的英文实在是太多了 ,搞不懂. 最后才知道是用公式seed(x+1) = [seed(x) + STE ...

随机推荐

  1. 转:cookie.setPath()用法

    原文地址:cookie.setPath()的用法 正常的cookie只能在一个应用中共享,即一个cookie只能由创建它的应用获得. 1.可在同一应用服务器内共享方法:设置cookie.setPath ...

  2. CloudStack和OpenStack该如何选择(如果准备选择OpenStack,请做好hack的准备。CloudStack的底层功能已经做的很完善了,更适合商用)

    国内做云计算的目前基本会在OpenStack和CloudStack中做一个选择.CloudStack 和OpenStack选哪一个,要根据自己的业务模式和研发力量来定. 作者:来源:cloudstac ...

  3. mysql拼接sql的语法concat()用法

    之前写了oracle拼接sql是用“||”,那么mysql也有自己的拼接的语法concat() concat()的基本语法是如下: 括号内的拼接内容语法和python中拼接显示字符串和变量.常量时一样 ...

  4. 洛谷P4198 楼房重建 单调栈+线段树

    正解:单调栈+线段树 解题报告: 传送门! 首先考虑不修改的话就是个单调栈板子题昂,这个就是 然后这题的话,,,我怎么记得之前考试好像有次考到了类似的题目昂,,,?反正我总觉着这方法似曾相识的样子,, ...

  5. Oracle内置函数SQLCODE和SQLERRM的使用

    在我们写proc程序中经常要有错误处理,在错误处理中我们经常要输出错误信息来给帮助我们分析和解决错误原因,从而更正数据.这时候就会用到SQLCODE和SQLERRM. SQLCode:数据库操作的返回 ...

  6. 关于ARMv8另外几个问题

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/qianlong4526888/article/details/27510675 问题1:支持ARMv ...

  7. svn .a文件上传不了

    最近mac电脑出现了问题,导致硬盘被格式化,所有文件都没了,打开app,一直缺少第三方文件libWeChatSDK.a,打开xcode文件变红了,找不到了,为了预防此类问题,在这里给出解决方法,如果没 ...

  8. MySQL 创建用户并分配用户权限

    mysql在最新的版本中会生成随机密码,存储在/etc/my.conf的文件中,但是大多数使用者不会在意这个,因为随机的密码识别性太差,所以我们可以自己配置数据库用户以及设置密码. 设置跳过密码登陆r ...

  9. 011-ThreadFactory线程工厂

    一.源码分析 ThreadFactory是一个线程工厂.用来创建线程.这里为什么要使用线程工厂呢?其实就是为了统一在创建线程时设置一些参数,如是否守护线程.线程一些特性等,如优先级.通过这个Tread ...

  10. PHP做APP接口时,如何保证接口的安全性??????????

    PHP做APP接口时,如何保证接口的安全性? 1.当用户登录APP时,使用https协议调用后台相关接口,服务器端根据用户名和密码时生成一个access_key,并将access_key保存在sess ...