poj2381解题报告

本文探讨了一种简单的线性同余随机数生成器(RNG),并提供了一个计算最长随机数序列间隙的C++实现。该算法通过不断迭代公式来生成随机数序列,并测量连续随机数之间的最大差距。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Random Gap
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 3538 Accepted: 871

Description

The pseudo-random number genegators (or RNGs for short) are widely used in statistical calculations. One of the simplest and ubiquitious is the linear congruence RNG, that calculates the n-th random number Rn as Rn = (aRn - 1 + c) mod m, where a, c and m are constants. For example, the sequence for a = 15, c = 7, m = 100 and starting value R0 = 1 is 1, 22, 37, 62, 37, 62, ...

Linear RNG is very fast, and can yield surprisinly good sequence of random numbers, given the right choice of constants. There are various measures of RNG quality, and your task is to calculate one of them, namely the longest gap between members of the sequence. More precisely, given the values of a, c, m, and R0, find such two elements Ri < Rj that:
  1. there are no other Rk that Ri ≤ Rk ≤ Rj,
  2. the difference Rj − Ri is maximal.

Input

Input contains integer numbers a c m R0.
0 ≤ a, c, R0 ≤ 107, 1 ≤ m ≤ 16000000, am + c < 232.

Output

Output should contain the single number -- the maximal difference found.

Sample Input

15 7 100 1

Sample Output

25
思路:这个题搞的头都大了。。。刚开始想用链表做,在有序链表中插入Rn,咋弄咋超时。。。最后不得不暴力了。。2***MS过了
看来暴力才是王道。。。::>_<::
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值