hdu_1014_Uniform Generator_201310141958
Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14213 Accepted Submission(s): 5562
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.
#include <stdio.h> int f(int m,int n)
{
int i=,t;
if(m>n)
{t=m;m=n;n=t;}
while(i)
{
i=n%m;
n=m;
m=i;
}
return n;
} int main()
{
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
{
int t=;
t=f(m,n);
if(t>)
{
printf("%10d%10d",m,n);
printf(" Bad Choice\n\n");
}
else
{
printf("%10d%10d",m,n);
printf(" Good Choice\n\n");
}
}
return ;
}
hdu_1014_Uniform Generator_201310141958的更多相关文章
随机推荐
- 如何使jquery性能最佳
转自 http://www.cnblogs.com/mo-beifeng/archive/2012/02/02/2336228.html 1. 使用最新版本的jQuery jQuery的版本更新很快, ...
- 湖南集训day5
难度:☆☆☆☆☆☆☆ /* 二分答案 算斜率算截距巴拉巴拉很好推的公式 貌似没这么麻烦我太弱了...... 唉不重要... */ #include<iostream> #include&l ...
- 使用HBuilder新建项目
依次点击文件→新建→选择Web项目(按下Ctrl+N,W可以触发快速新建(MacOS请使用Command+N,然后左键点击Web项目)) 如上图,请在A处填写新建项目的名称,B处填写(或选择)项目保存 ...
- strcpy 和 memcpy自实现
都是套路,详见代码注释: #include <stdio.h> #include <assert.h> #include <iostream> using name ...
- 6.11---multipartfile在哪个jar包下---6.11---uuid---swagger上传图片包错去掉注解响应体
<dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupl ...
- 小小的IP,大大的耦合,你痛过吗?
什么是耦合? 耦合,是架构中,本来不相干的代码.模块.服务.系统因为某些原因联系在一起,各自独立性差,影响则相互影响,变动则相互变动的一种架构状态. 感官上,怎么发现系统中的耦合? 作为技术人,每每在 ...
- js基础---元素操作时字符串拼接
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- service里设置websocket心跳并向fragment发送数据
垃圾小白写了自己看的 /** * service 文件 */ public class SocketService extends Service { //自己定义接口用来传参 private sta ...
- 【转】升级还是权谋?从USB PD 2.0到3.0
原文出处 http://www.eetop.cn/blog/html/43/n-433743.html 如同iPhone的出现,才让智能机真正主导手机市场一样,Type-C口发布后,USB PD才正式 ...
- Linq处理decimal字段汇总Sum()为NULL
xxxxxxxx.Sum(f => f.jifen).GetValueOrDefault(0)