HDU 1014 Uniform Generator(模拟和公式)

该博客主要讨论了HDU 1014问题,即“Uniform Generator”。内容涉及如何通过公式法判断给定的step和mod是否能确保生成所有可能的序列值,重点在于分析最大公约数(GCD)与序列生成的关系。当GCD(step, mod)为1时,序列会包含所有0到mod-1的数,否则可能会跳过某些数值。文章还提到了扩展结论,引入了乘法因子a和步长b的情况,同样需要GCD(a, mod)和GCD(b, mod)都等于1来保证序列的完整性。" 122835822,11724618,Java反射机制详解与应用,"['Java', '反射', '类加载', '封装', '构造方法']
摘要由CSDN通过智能技术生成

传送门:

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

Uniform Generator

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


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 dist
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值