Uniform Generator

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 21176 Accepted Submission(s): 8294

Problem Description

Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form

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.

Input

Each line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).

Output

For 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

小小的空格PE好几次,基础不扎实啊

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
using namespace std;
const int Max=110000;
bool vis[Max];
int main()
{
int STEP,MOD;
while(cin>>STEP>>MOD)
{
memset(vis,false,sizeof(vis));
vis[0]=true;
int sum=0;
int ans=1;
while(1)
{
sum=(sum+STEP)%MOD;
if(vis[sum])
{
break;
}
else
{
vis[sum]=true;
ans++;
}
}
if(ans<MOD)
{
printf("%10d%10d Bad Choice\n\n",STEP,MOD);
}
else
{
printf("%10d%10d Good Choice\n\n",STEP,MOD);
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏的更多相关文章

  1. 认识C++中的临时对象temporary object 分类: C/C++ 2015-05-11 23:20 137人阅读 评论(0) 收藏

    C++中临时对象又称无名对象.临时对象主要出现在如下场景. 1.建立一个没有命名的非堆(non-heap)对象,也就是无名对象时,会产生临时对象. Integer inte= Integer(5); ...

  2. 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏

    动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...

  3. Windows7下QT5开发环境搭建 分类: QT开发 2015-03-09 23:44 65人阅读 评论(0) 收藏

    Windows7下QT开法环境常见搭配方法有两种. 第一种是:QT Creator+QT SDK: 第二种是:VS+qt-vs-addin+QT SDK: 以上两种均可,所需文件见QT社区,QT下载地 ...

  4. short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...

  5. short-path problem (Dijkstra) 分类: ACM TYPE 2014-09-01 23:51 111人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...

  6. 树莓派安装mjpg-streamer视频监控 分类: Raspberry Pi 2015-04-12 23:41 144人阅读 评论(0) 收藏

    原来使用Motion在树莓派上跑1280x720分辨率的三颗摄像头.占用内存太严重,关闭诸多功能之后还是不行.故转战mjpg-streamer. 首先安装所需软件 sudo apt-get insta ...

  7. 【从0到1学Web前端】CSS定位问题三(相对定位,绝对定位) 分类: HTML+CSS 2015-05-29 23:01 842人阅读 评论(0) 收藏

    引子: 开始的时候我想先要解决一个问题,怎么设置一个div盒子撑满整个屏幕? 看下面的html代码: <body> <div id="father-body"&g ...

  8. 循环队列 分类: c/c++ 2014-10-10 23:28 605人阅读 评论(0) 收藏

    利用线性表实现队列,为了有效利用空间,将其设计为循环结构,防止假溢出:牺牲一个存储单元以区分队空.队满. 设front队头,rear队尾,N为顺序表大小 队空:rear==front 队满:(rear ...

  9. 链表中用标兵结点简化代码 分类: c/c++ 2014-09-29 23:10 475人阅读 评论(0) 收藏

    标兵结点(头结点)是在链表中的第一个结点,不存放数据,仅仅是个标记 利用标兵结点可以简化代码.下面实现双向链表中的按值删除元素的函数,分别实现 带标兵结点和不带标兵结点两版本,对比可见标兵结点的好处. ...

随机推荐

  1. object_id的用法

    OBJECT_ID: 返回数据库对象标识号. 语法 OBJECT_ID ( 'object' ) 参数 'object' 要使用的对象.object 的数据类型为 char 或 nchar.如果 ob ...

  2. Summary: Merge Sort of Array && 求逆序对

    常用算法(后面有inplace版本): package ArrayMergeSort; import java.util.Arrays; public class Solution { public ...

  3. 初始化 Gradle 工程目录(转自: 隔叶黄莺 Unmi Blog)

    最近重新在 Eclipse 中打开旧的 Maven 项目,总有些什么错误,备受折磨.期间试手了 Ant+Ivy, 现今试用了下 Gradle,感觉不错,它应该才是我真想要的,Maven 差不多该扔到一 ...

  4. nyist 673 悟空的难题

    http://acm.nyist.net/JudgeOnline/problem.php?pid=673 悟空的难题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 ...

  5. C++之路进阶——codevs2313(星际竞速)

    2313 星际竞速 2010年省队选拔赛山东  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master     题目描述 Description 10 年一度的银河系 ...

  6. C++之路进阶——bzoj1455(罗马游戏)

    F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser  gryz2016 Logout 捐赠本站 Notice:由于本OJ ...

  7. mongodb版本管理

    使用gradle. 查找最新版本http://mvnrepository.org/ compile "org.mongeez:mongeez:0.9.6" 配置spring < ...

  8. [fedora21]给fedora21安装fcitx输入法

    如果已经安装了ibus,需要卸载ibus:   sudo yum remove ibus; 安装fcitx: sudo yum install fcitx fcitx-pinyin fcitx-con ...

  9. enum与typedef enum的用法

    一,两者的用法 枚举类型定义用关键字enum标识,形式为: enum 标识符 { 枚举数据表 }:枚举数据(枚举常量)是一些特定的标识符,标识符代表什么含义,完全由程序员决定.数据枚举的顺序规定了枚举 ...

  10. Sql Server 检测死锁的SQL语句

    首先创建一个标量值函数DigLock,用来递归检测SqlServer中的每一个会话是否存在加锁循环,如果该函数最终返回1则表示检测到了加锁循环 (也就是说检测到了死锁),如果最终返回0则表示没有检测到 ...