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 ...
随机推荐
- 转:Java中Scanner类和BufferReader类之间的区别
原文地址:https://blog.csdn.net/u014717036/article/details/52227782 java.util.Scanner类是一个简单的文本扫描类,它可以解析基本 ...
- LeetCode 709 To Lower Case 解题报告
题目要求 Implement function ToLowerCase() that has a string parameter str, and returns the same string i ...
- 洛谷P3041 视频游戏的连击Video Game Combos [USACO12JAN] AC自动机+dp
正解:AC自动机+dp 解题报告: 传送门! 算是个比较套路的AC自动机+dp趴,,, 显然就普普通通地设状态,普普通通地转移,大概就f[i][j]:长度为i匹配到j 唯一注意的是,要加上所有子串的贡 ...
- python练习题-day4
1.写代码,有如下列表,按照要求实现每一个功能 li = ["alex", "WuSir", "ritian", "barry&q ...
- 原生js可视加载图片、延迟加载、懒加载
<script> //既视加载//var oBtn = document.getElementsByTagName('button')[0];var aImages = document. ...
- 报错解决——OSError: libdarknet.so: cannot open shared object file: No such file or directory
在python目录下打开终端,输入 python darknet.py 结果报错 Traceback (most recent call last): File “darknet.py”, line ...
- Windows 7系统下安装和卸载删除IE的方法
1.首先按下 Windows +R 键打开“运行”的窗口,请输入“appwiz.cpl”. 2.在「程序和功能」窗口上按下左上的「查看已安装的更新」. 3.找到「Windows Internet Ex ...
- jQuery-velocity.js 插件的简易使用
初识Velocity动画,感觉它并没有那么强大,但是渐渐感觉它的ui动画可以让我们简易的使用到我们的项目中. Velocity动画的简介: 下载地址:http://www.julian.com/res ...
- asp.net几个重要对象
DataSet是用来做连接sql的一种方法,意思是把数据库的副本存在应用程序里,应用程序开始运行时,把数据库相关数据保存到DataSet.DataTable表示内存中数据的一个表.常和DefaultV ...
- 【LeetCode每天一题】Two Sum(两数之和)
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...