Uniform Generator
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.
InputEach line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).
OutputFor each line of input, your program should print the STEP value right- justified in columns 1 through 10, the MOD value right-justified in columns 11 through 20 and either "Good Choice" or "Bad Choice" left-justified starting in column 25. The "Good Choice" 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.
Sample Input
3 5
15 20
63923 99999
Sample Output
3 5 Good Choice
15 20 Bad Choice
63923 99999 Good Choice
思路 : 水了两晚上的题,差点淹死.......这个题有两种做法,首先就是普通做法,其次就是求两个数最大公约数是不是一;
第一种方法:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int s,mod,i;
while(~scanf("%d%d",&s,&mod))
{
int a[100001] = {0},seed=0;
while(!a[seed]){
a[seed] = 1;
seed = (seed+s)%mod;
}
for(i=0;i<mod;i++){
if(a[i] == 0){
printf("%10d%10d Bad Choice\n\n",s,mod);break;
}
}
if(i==mod){
printf("%10d%10d Good Choice\n\n",s,mod);
}
}
return 0;
}
第二种方法
#include <bits/stdc++.h>
using namespace std;
int main()
{
int step,mod1,t;
while(scanf("%d%d",&step,&mod1)==2)
{
printf("%10d%10d",step,mod1);
while(mod1)
{
t = step%mod1;
step = mod1;
mod1 = t;
}
printf(" %s\n\n",step == 1? "Good Choice":"Bad Choice");
}
return 0;
}
欢迎批评指正。
Uniform Generator的更多相关文章
- HDU 1014:Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- uva 408 Uniform Generator
Uniform Generator Computer simulations often require random numbers. One way to generate pseudo-ran ...
- 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 Uniform Generator Time Limit: 2000/1000 MS (Java ...
- (杭电 1014)Uniform Generator
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDOJ 1014 Uniform Generator(公约数问题)
Problem Description Computer simulations often require random numbers. One way to generate pseudo-ra ...
- 1014 Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
随机推荐
- mabytis的xml一些写法
1.jdbcType=TIMESTAMP 而不是 jdbcType=DATETIME myabtis 3.4.6 版本jar包中:jdbcType枚举: ARRAY(Types.ARRAY), BIT ...
- Struts2中类数据封装的方式
第一种方式:属性驱动提供对应属性的set方法进行数据的封装.表单的哪些属性需要封装数据,那么在对应的Action类中提供该属性的set方法即可.表单中的数据提交,最终找到Action类中的setXxx ...
- 遇到的一个移动端从下往上过渡的弹框,在Android下过渡动画的优化问题。
优化之前: /* 分享弹框样式 */ .popUpDiv { width: 100vw; height: 100vh; transition: all 0.5s ease; position: fix ...
- npm常用模块
https://blog.csdn.net/heliumlau/article/details/70577727
- linux命令中的参数前的一横(-)和两横(--)的区别
在解释这些区别之前我们先了解一下有关linux的背景知识,这个需要大家先认真看完就会对这些区别有更深入的了解,对linux也有更深的了解. 关于System V和BSD风格以及他们与Linux的关系: ...
- 浅谈FastJson的TypeReference用法
简单描述:看同事提交的代码,发现有一行代码 似曾相识,但却朦朦胧胧,ε=(´ο`*)))唉很明显自己没掌握呗,于是乎,就百度了一下 干货:对进行泛型的反序列化,使用TypeReference可以明确的 ...
- Web Penetration Testing
1.国外使用的一款在线工具,对web的信息收集很有帮助 地址http://archive.org , WayBack Machine 主界面如下:对百度存档的历史信息进行查询. 2.IP地址归属信息 ...
- Oracle下载 OPatch
今天被朋友问及,如何下载OPatch ...我当时有些凌乱的.事后想想,人与人的思维是不同的,对待同一个问题,有人觉得很简单,有人觉得无从下手 . 乱不多说了.开始说明下吧. 1. 首先要有一个MOS ...
- iptables-snat-dnat-设置
nat internet iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.255.0 -o eth1 -j SNAT --to-source ...
- MySQL查看库表的大小
MySQL数据库空间使用情况查询 如果想知道MySQL数据库中每个表占用的空间.表记录的行数的话,可以打开MySQL的 information_schema 数据库.在该库中有一个 TABLES 表, ...