HDU 1014 Uniform Generator(题解)
Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32990 Accepted Submission(s): 13081
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.
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.
15 20
63923 99999
15 20 Bad Choice
63923 99999 Good Choice
#include<iostream>
#include<cstdio> using namespace std; int gcd(int a, int b)
{
return b == ? a: gcd(b, a % b);
}
int main()
{
int a, b;
while ( cin >> a >> b)
{
printf("%10d%10d ", a, b);
printf(gcd(a, b) == ? "Good Choice": "Bad Choice");
printf("\n\n");
}
}
所以最后也没看明白题目说什么T^T
HDU 1014 Uniform Generator(题解)的更多相关文章
- HDU 1014 Uniform Generator 题解
找到规律之后本题就是水题了.只是找规律也不太easy的.证明这个规律成立更加不easy. 本题就是求step和mod假设GCD(最大公约数位1)那么就是Good Choice,否则为Bad Choic ...
- 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 数论
摘取于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 ...
随机推荐
- 转:string.Format格式化用法
String.format()方法使用说明(比较详细) 地址:https://blog.csdn.net/thc1987/article/details/17528093 典型案例 原文地址:http ...
- LeetCode 690 Employee Importance 解题报告
题目要求 You are given a data structure of employee information, which includes the employee's unique id ...
- 1、python同级目录及子目录模块引入
2个模块在同一个包内时(即引入和被引入的2个py文件在同一个目录下),直接引入模块名 1.引入与被引入模块或包在同一目录下时,直接引入模块名或者包名import modulename.py或者impo ...
- Eclipse设置注释模板和工作空间背景色为豆沙绿
Eclipse Version: Photon Release (4.8.0). 首先上图,根据图上的步骤即可完成注释模板的设置. 1 如何设置eclipse注释模板的日期格式 在eclipse的 P ...
- nodejs 学习一 process.execPath 、 __dirname、process.cwd()的区别
process.execPath node.exe的绝对路径 __dirname 当前执行到__dirname文件文件路径 process.cwd() 启动node命令的目录的绝对路劲
- JavaScript学习(六)
这里要注意: 1.num为NaN(因为str的开头不是数字) 2.NaN和NaN是不等的 3.NaN也是number.
- SQL SERVER 基于数据库镜像的主从同步(数据库镜像实践汇总)
SQL SERVER 基于数据库镜像的主从同步 Author:chaoqun.guo createtime:2019-03-26 目录 SQL SERVER 基于数据库镜像的主从同步... 1 ...
- ntpdata 同步时间
ntpdate用来同步时间 [root@localhost ~]# yum install -y ntp [root@localhost ~]# ntpdate time.windows.com # ...
- Elemet-技巧
<el-table-column prop="> </el-table-column> 效果: append-to-body 解决el-dialog 弹窗遮罩为题 & ...
- Kinect2.0相机标定
尝试进行Kinect2.0相机进行标定 1. Color镜头标定 $(u_{rgb},v_{rgb},1)=W_{rgb}*(x,y,z)$ Calibration results after opt ...