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的更多相关文章
随机推荐
- codevs1163访问艺术馆(树形dp)
1163 访问艺术馆 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 皮尔是一个出了名的盗画者,他经过数月的精心准备, ...
- IOS上微信在输入框弹出键盘后,页面不恢复,下方有留白,有弹窗弹出时页面内容感应区域错位
问题说明: ios中,键盘的弹起,页面会往上挪动,使输入框展示在页面中间,键盘隐藏页面会下挪恢复原状. 在微信移动端,ios页面不恢复,下方有留白. 收起键盘的瞬间,如果有弹窗弹出,此时时页面内容应区 ...
- Python/Django 批量下载Excel
一.前提 项目上需求的变更总是时时发生的,应对需求的我们,也只能变更我们代码,所以.继前两篇之后,我们的批量下载诞生了 二.安装 本文使用zipstream库进行压缩,安装方式:pip install ...
- 尝试安卓与js交互
1.android中利用webview调用网页上的js代码. Android 中可以通过webview来实现和js的交互,在程序中调用js代码,只需要将webview控件的支持js的属性设置为true ...
- Unity学习-预制(四)
预制即克隆 比如要模拟一个下雨的场景,天下掉下来一颗一颗的雨滴.如果此时,我们给每一个雨滴创建一个对象的话,那会很浪费资源,而且也没必要,因为所有的雨滴是相同的.这个时候就使用到了预制,一种可以被重复 ...
- AdminLTE介绍和zTree的简单使用
一.AdminLTE介绍 1.介绍 AdminLTE是一个开源的后台控制面板和仪表盘 WebApp 模板,是建立在Bootstrap3框架和JQuery之上的开源模板主题工具,它提供了一系列响应的 ...
- Mac sierra下 wget安装
本文由@ray 出品,转载请注明出处. 文章链接:http://www.cnblogs.com/wolfray/p/8040699.html 没有Wget的日子是非常难过的,强大的Mac OS 下安 ...
- Android开发中常用的ListView列表的优化方式ViewHolder
在Android开发中难免会遇到大量的数据加载到ListView中进行显示, 然后其中最重要的数据传递桥梁Adapter适配器是常用的,随着市场的需 求变化ListView'条目中的内容是越来越多这就 ...
- SQL基本操作——创建索引
CREATE INDEX 语句用于在表中创建索引.在不读取整个表的情况下,索引使数据库应用程序可以更快地查找数据. 索引:您可以在表中创建索引,以便更加快速高效地查询数据.用户无法看到索引,它们只能被 ...
- 【译】x86程序员手册08 -2.6中断和异常
2.6 Interrupts and Exceptions 中断和异常 The 80386 has two mechanisms for interrupting program execution: ...