HDU 1014:Uniform Generator
Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24381 Accepted Submission(s): 9642
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.
message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. Otherwise, your program should print the message "Bad Choice". After each output test set, your program
should print exactly one blank line.
3 5
15 20
63923 99999
3 5 Good Choice 15 20 Bad Choice 63923 99999 Good Choice
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方…
#include<stdio.h>
int gcd(int a,int b)
{
return gcd(b,a%b);
if(!b)return a;
}
int s,m;
int main()
{
{
while(~scanf("%d%d",&s,&m))
if(gcd(s,m)==1)printf("%10d%10d Good Choice\n\n",s,m);
else printf("%10d%10d Bad Choice\n\n",s,m);
}
return 0;
}
HDU 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 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目意思:给出 STEP 和 MOD,然后根据这个公式:seed(x+1) = [seed(x) ...
- HDU 1014 Uniform Generator 欧几里得
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这 ...
- HDU 1014 Uniform Generator 题解
找到规律之后本题就是水题了.只是找规律也不太easy的.证明这个规律成立更加不easy. 本题就是求step和mod假设GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choic ...
- hdu 1014 Uniform Generator 数论
摘取于http://blog.csdn.net/kenden23/article/details/37519883: 找到规律之后本题就是水题了,不过找规律也不太容易的,证明这个规律成立更加不容易. ...
- HDU 1014 Uniform Generator(最大公约数,周期循环)
#include<iostream> #include <cstdio> #include <cstring> using namespace std; int m ...
- 1014 Uniform Generator ACM
http://acm.hdu.edu.cn/showproblem.php?pid=1014 题目的英文实在是太多了 ,搞不懂. 最后才知道是用公式seed(x+1) = [seed(x) + STE ...
随机推荐
- C# WebApi传参之Get请求-AJAX
最近悟出来一个道理,在这儿分享给大家:学历代表你的过去,能力代表你的现在,学习代表你的将来. 十年河东十年河西,莫欺少年穷. 学无止境,精益求精 在介绍本篇博客之前,先来温故下AJax的请求, ...
- 查看oracle 数据库的DBID
(1)使用rman查看$ rman target /Recovery Manager: Release 11.2.0.4.0 - Production on Fri Jun 12 03:20:19 2 ...
- 12C清理asm磁盘组和文件
磁盘清理(disk scrub)可以检查逻辑坏块,并使用镜像数据自动修复数据(必须是normal.high冗余级别).磁盘清理过程和磁盘组的rebalance相结合,可以减少对I/O资源的使用.清理过 ...
- springframework开源代码导入eclipse
从毕业到现在已经3个多点年头了,开源框架也用过不少.对于j2ee开发来说,spring框架是是最流行的轻量级可选的框架之一,如果还停留在只会使用,而对源代码不研究是不行的. 话不多说 先从导入代码开始 ...
- String类型方法
String类型 //1.返回长度 length var a="lynn_hello"; console.log(a.length); //2.相加 concat() 返回一个新的 ...
- sql server create foreign key
in table design view(right click table and choose design), right click on a column, and select 'rela ...
- Ruby On Rails经典书籍下载地址
Web开发敏捷之道-应用Rails进行敏捷Web开发 http://vdisk.weibo.com/s/t47M5Q3WInwc RUBY ON RAILS入门经典 http://downlo ...
- java数组转化成集合
package com.shb.web; import java.util.Arrays;import java.util.List; import com.sun.xml.internal.ws.u ...
- ViewModel在MVC3中的应用:一个view显示多个model
在mvc3中,默认是一张数据表对应一个model,一个视图 view只显示一个model. 但是有些时候,我们一个视图上可能需要显示多个model的内容,即一个网页可能要展示多张表的信息,那怎么办呢, ...
- 远程mysql服务器无法连接解决方案
错误现象:Habon被拒绝. 远程服务器无法连接从两个方面看 1.是否能ping通远程服务器 windows下查看防火墙是否已关闭 linux下查看iptables等 2.数据库是否有开用户管理权限 ...