1014 Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28661 Accepted Submission(s): 11402
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.
15 20
63923 99999
15 20 Bad Choice
63923 99999 Good Choice
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define N 100000
int main()
{
int step,mod;
while(scanf("%d%d",&step,&mod)!=EOF)
{
int a[N],m=;
a[]=;
for(int i=;i<mod;i++)
{
a[i]=(a[i-]+step)%mod;
}
sort(a,a+mod);
for(int i=;i<mod;i++)
{
if(a[i]!=i)
{
m=;
break;
}
}
if(m==)
{
printf("%10d%10d",step,mod);
printf(" Bad Choice\n");
}
else
{
printf("%10d%10d",step,mod);
printf(" Good Choice\n");
}
printf("\n");
}
return ;
}
或者(判断两个数是否互质)
#include<stdio.h>
int hz(int t,int m)
{
for(int i=;i<=t&&i<=m;i++)
if(t%i==&&m%i==)
return ;
return ;
}
int main()
{
int t,m;
while(scanf("%d%d",&t,&m)!=EOF)
{
if(hz(t,m))
printf("%10d%10d Good Choice\n\n",t,m);
else
printf("%10d%10d Bad Choice\n\n",t,m);
}
}
1014 Uniform Generator的更多相关文章
- HDU 1014 Uniform Generator(模拟和公式)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java ...
- HDU 1014 Uniform Generator【GCD,水】
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1014:Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1014 Uniform Generator(题解)
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1014.Uniform Generator 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目意思:给出 STEP 和 MOD,然后根据这个公式:seed(x+1) = [seed(x) ...
- HDOJ 1014 Uniform Generator(公约数问题)
Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...
- HDU 1014 Uniform Generator 欧几里得
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这 ...
- 1014 Uniform Generator ACM
http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目的英文实在是太多了 ,搞不懂. 最后才知道是用公式seed(x+1) = [seed(x) + STE ...
- HDU 1014 Uniform Generator 题解
找到规律之后本题就是水题了.只是找规律也不太easy的.证明这个规律成立更加不easy. 本题就是求step和mod假设GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choic ...
随机推荐
- 开发使用Node.js的一个小技巧
Node.js作为可以在服务器端运行的一门语言,其处理长连接.多请求的优势受到各大编程爱好者的追捧. 但是在开发调试方面却极为不方便,因为每次改动代码后,都需要终止当前进程,重启服务器.supervi ...
- Ioc在重构代码中的应用
最近lz在写抓工商公式系统(http://www.gsxt.gov.cn/index.html)的爬虫,其中的难点就是在怎么过极验验证码,搞的我不要不要的!如下: 简直是各种坑,被搞的死去活来以后还是 ...
- ubuntu如何进入local、bin目录
回到home目录,输入命令:cd /usr/local 若要进入bin目录,输入命令:cd /usr/local/bin
- ubuntu14.04下chrome浏览器的安装
ubuntu 64位 1.下载chrome安装包: sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_ ...
- 纪念一下java学习之第一个get请求。
环境,变量及工具: 1.java jdk1.8.X 2.tomcat 8.5.11 3. 环境变量: CATALINA_HOME: tomcat安装地址 JAVA_HOME: JDK安装地址 ...
- python终端中退格键,方向键不能使用
在安装Python的时候先安装 yum install readline-devel.x86_64 -y 如果python已经安装过了就重新安装 ./configure make all mak ...
- 服务器证书安装配置指南(SLB)
一.生成证书请求 1.下载CSR生成工具 您需要使用CSR生成工具来创建证书请求. 下载AutoCSR: http://www.itrus.cn/soft/autocsr.rar 2.生成服务器 ...
- iOS 文本转语音(TTS)详解:Swift
上一篇博客讲解了iOS的speech FrameWork语音识别的功能:http://www.cnblogs.com/qian-gu-ling/p/6599670.html,对应的这篇博客就写一下文本 ...
- 网站建设常用JQuery插件整理
1.jQuery.lazyload 作用:延迟加载网站图片,常用于电商网站.图片展示网站,对于提高网站打开速度比较有效. 2.Owl Carousel 作用:图片滚动特效.响应式传送带插件,特点是支持 ...
- 老李分享:Uber究竟是用什么开发语言?
poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-845052 ...