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 ...
随机推荐
- CDB中plug PDB
CDB中plug PDB 先决条件: ·CDB要能够访问之前被unplugged 的pdb的xml文件.如果不能访问,需要使用dbms_pdb.recover创建一个xml文件 ·CDB要能够访问到该 ...
- 【转】Java多线程编程中易混淆的3个关键字( volatile、ThreadLocal、synchronized)总结
概述 最近在看<ThinKing In Java>,看到多线程章节时觉得有一些概念比较容易混淆有必要总结一下,虽然都不是新的东西,不过还是蛮重要,很基本的,在开发或阅读源码中经常会遇到,在 ...
- git打tag 三步骤
git status git tag publish/1.0.0 git push origin publish/1.0.0
- MyEclipse6.5注册码(转)
新装的MyEclipse6.5在网上找了半天的注册码,都不可用.将下面的代码放在MyEclipse下运行后,可以得到注册码.这相当于一个注册机.我得到的如下: administrator nLR8ZC ...
- Java基础之创建窗口——使用流布局管理器(TryFlowLayout)
控制台程序. FlowLayout把组件放在容器的连续行中,使每一行都放置尽可能多的组件.如果某行已满,就放在下一行.工作方式类似于文本处理器把单词放在行中.主要用途是放置按钮,但也可以用来放置其他组 ...
- Snapchat面经(师兄的)
给一个LinkedList环,给其中任一个节点的reference,求删去LinkedList中所有value=k的点 我的想法:假设给定的点事ListNode oneNode, 设置ListNode ...
- 创建Java类并实例化深入理解
package com.sanguosha.java; import java.util.Scanner;//导入包 public class TestPerson { public static v ...
- 20145207 《Java程序设计》第一周学习总结
不好意思,来晚了 别的先不说,先道个歉,放假前跟娄老师多少发生点矛盾,望原谅. 假期忙实习还有一些其他事情,为了认真对待这门课,把剩下的时间留下来,争取一天一章来弥补. 由于没选课加上另一门课没开 ...
- linux挂接U盘
挂接U盘fdisk -lDisk /dev/sdd: 131 MB, 131072000 bytes/dev/sdd1 * 1 889 127983+ b Win95 FAT32#mkdir -p / ...
- 安装kingroot之后的残留
/system/usr/icu/icusuflag.conf/system/usr/ikm/ikmsu/system/usr/iku//system/usr/attrch/system/etc/ins ...