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. 转:ActiveMQ的作用总结(应用场景及优势)

    原文地址: ActiveMQ的作用总结(应用场景及优势) 业务场景说明: 消息队列在大型电子商务类网站,如京东.淘宝.去哪儿等网站有着深入的应用, 队列的主要作用是消除高并发访问高峰,加快网站的响应速 ...

  2. 转:JAVA守护线程

    原文地址:https://www.cnblogs.com/wxgblogs/p/5417503.html 详细内容看原文~  ,写的挺好的 在Java中有两类线程:User Thread(用户线程). ...

  3. c语言指针应用

    指针变量指向数组元素: #import <stdio.h> int main() { int a[10]={1,2,3,4,5,6,7,8,9,0}; int *p; p=a; for ( ...

  4. finecms在任意页面调用栏目名称和地址等

    finecms如何调用栏目名称和地址呢?在任意页面.我们有时需要在不同的页面调用某个栏目名,怎么调用比较快呢?ytkah整理了一些快速调用语句方便查找 栏目名称:{dr_cat_value(栏目id, ...

  5. Redis和Memcache的区别是什么

    Redis和Memcache都是内存数据库,但它们之间还是有区别的,跟着ytkah看看Redis和Memcache的区别吧 Redis 支持多种数据结构,如string,list,dict,set,z ...

  6. Mysql索引基础原理

    索引的概念 索引是特殊数据结构:  定义在查找时作为查找条件的字段 索引实现在存储引擎 功能: 1.约束数据 2.加速查询 优点: 索引可以降低服务需要扫描的数据量,减少了IO次数 索引可以帮助服务器 ...

  7. 005-优化web请求一-gzip压缩、http缓存控制和缓存校验[Pragma、Expires、Cache-Control、max-age、Last-Modified、用户刷新访问、避免过度304]

    优化Web应用的典型技术:缓存控制头信息.Gzip.应用缓存.ETag.反应型技术[异步方法调用和WebSocket] 一.模板缓存 spring.thymeleaf.cache=true sprin ...

  8. VS2017使用Git进行源代码管理

    步骤一:将解决方案添加到源代码管理 步骤二:进入团队资源管理器 双击存储库项目进入Git操作页面. 步骤三:同步本地代码到远程仓库 选择同步功能 步骤四:发布代码到Git 点击之后输入你要发布的git ...

  9. vue-cli 3.x脚手架配置并使用vux

    https://blog.csdn.net/Honnyee/article/details/82181620

  10. (转)Thread中yield方法

    先上一段代码 public class YieldExcemple { public static void main(String[] args) { Thread threada = new Th ...