HDU 1014 Uniform Generator

Uniform Generator 题目: 1010 问题描述 计算机模拟通常需要随机数。生成伪随机数的一种方法是通过 种子(x+1)=[种子(x)+步骤]%MOD 其中“%”是模运算符。 这样的函数将生成介于0和MOD-1之间的伪随机数(seed)。这种形式的函数的一个问题是,它们总是一遍又一遍地生成相同的模式。为了最小化这种影响,仔细选择步长和MOD值可以使所有值在(包括)0和MOD-1之间均匀分布。 例如,如果STEP=3和M... 阅读详情

                                    Uniform Generator

                    http://acm.hdu.edu.cn/showproblem.php?pid=1014   

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21831    Accepted Submission(s): 8556


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
 

题意:给出两个数step和mod,判断能否通过给定的函数生成0到mod-1间的任意数,并且按要求格式输出。

解题思路:通过分析模拟可以得出当输入两数step,mod最大公约数为1时就能满足题意,即转为判断两数是否为素数即可,但要输出格式,这是个大坑,最好用c输出。

复杂度分析: 时间复杂度:o(0)
空间复杂度:o(0)


#include<iostream>
#include<cstdio>
 #include<iomanip>
 using namespace std;
 int main()
 {
     int step,mod,r,a,b;
     while(cin>>step>>mod && mod)
     {
         a=step>mod?step:mod;
         b=step<mod?step:mod;
         while(b)
         {
             r=a%b;
             a=b;
             b=r;
         }
         if (a==1)  printf("%10d%10d    Good Choice\n\n", step, mod);
          else      printf("%10d%10d    Bad Choice\n\n", step, mod);
     }
     return 0;
 }
【从零开始学习 SystemVerilog】1.1、SystemVerilog 概述 阅读详情

相关推荐

数值天气预报期末复习

数值天气预报期末复习

m0_60394632的博客 7679

HDU 1014 Uniform Generator(模拟和公式)

&#13; 传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1014 Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33120    ...

Y先森0.0 278

WIFI 相关的频偏调试以及天线调试记录

WIFI RF 相关的频偏调试以及天线调试 1,频率误差(Frequency Error) 频率误差(Frequency Error):表征射频信号偏离该信号所处信道中心频率的大小,单位PPM。频偏误差要求范围如下表。 频偏越小越好。PPM的计算公式如下: 问题: 我们ESP8089认证测试的时候频偏测试超了。需要修改哪些呢。 测试频率点在2.411865385GHz 宣称点:2.412GHz 频率偏移计算:{(2.412GHz-2.411865385GHz)÷2...

armkits的博客 1万+

Uniform Generator(水题)

可以暴力求解,求mod次的种子然后统计每个数字出现次数 也可以求是否互质(可以根据hash表的设计来理解互质就能good choice原因) #include<iostream> #include<cstring> #include<cstdio> using namespace std; const int N = 100010; int vis[N]; in...

qq_45520541的博客 201

在天问block环境下LU-ASR01与51单片机的基础运用

正确步骤将模块和电脑连接后,仍然显示未连接(如4.1中图片中的编译下载后面显示未连接),可以尝试关闭软件后尝试,如果仍然不行换一条type-c线再试;以上方式都不行,可能要怀疑ASR01硬件损坏,跟商家联系!!!

BUG7073的博客 1万+

VirtualLab初学者教程-1.用户界面

目录前言一、VirtualLab Fusion简介1.软件2.内置工具箱:二、用户界面认识1.上方菜单栏2.右侧面主窗口3.底部窗口附 前言 感觉做VirtualLab的资料不是特别多,可能用的朋友也比较少吧,笔者最近也因为大创需要刚刚开始入门,把网上有的英文资料整理了一下,加了一点自己的内容发出来希望帮助更多在学习中的朋友,有用词不当之处还请多多包涵。 一、VirtualLab Fusion简介 因为是第一讲,简单啰嗦一下软件本身,参考官方介绍。 1.软件 VirtualLab是由德国LightTran

ClaireTang1的博客 2万+

hdu 1014

Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10856    Accepted Submission(s): 4291 Problem Description Computer si

ysc504的专栏 834

Android GWP-Asan机制详解

基本用途:GWP-ASan是一种原生内存分配器功能,在内存分配时额外记录一些信息,用于检测DOUBLE_FREE、USE_AFTER_FREE、INVALID_FREE、BUFFER_OVERFLOW、BUFFER_UNDERFLOW五种内存错误问题。

专注于系统快稳省领域 4143

hdu 1014 Uniform Generator

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1014   题目描述: Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11534    Acc

心之所向,无惧无悔! 1369

advanced installer 打包Flutter的Windows程序安装包(基本打包、开机自启、定时自动检测升级、包含卸载程序)

advanced installer 打包Flutter的Windows程序安装包(基本打包、开机自启、定时自动检测升级、包含卸载程序)

qq_45634989的博客 2878

华为od 面试八股文_操作系统_01_含答案

华为od 面试八股文_操作系统_01_含答案

MISAYAONE的博客 3275

HDU 1014 Uniform Generator 欧几里得

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这些数是不是能够包含0~MOD-1。如果产生不了就输出“Good Choice”,否则输出“Bad Choice”。 2. 全部假使x从0开始,设STEP为a,MOD为b。如果说a,b存...

ddqb3235的博客 207

【TC3xx芯片】TC3xx芯片看门狗复位的默认行为分析

TC3xx芯片看门狗复位的默认行为分析

qq_36056498的博客 350

Uniform Generator hdu-1014

题目来源:hdu-1014 Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 22038 Accepted Submission(s): 8671 Problem Descriptio

暮光乐鱼的博客 569

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

HDU1014——Uniform Generator,HDU1015——Safecracker,HDU1016——Prime Ring Problem

目录HDU1014——Uniform Generator题目描述运行代码代码思路HDU1015——Safecracker题目描述运行代码代码思路优化建议HDU1016——Prime Ring Problem题目描述运行代码代码思路Problem - 1014 代码思路 定义函数:函数:Problem - 1015 代码思路 函数定义:函数用于检查五个字母是否互不相同。函数用于降序排序字母。主函数逻辑:减少不必要的比较:避免不必要的ASCII转换:由于已经降序排序,可以直接使用字母在数组中

u014114223的博客 1032

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【基础题】HDU1014 Uniform Generator

题目 HDU1014 Uniform Generator 题目分析 这个题目是根据函数生成伪随机数,给定step和mod,在对于函数的重复中会生成一系列伪随机数,这一系列伪随机数可能会出现均匀分布的情况,就是会出现0~mod-1中的每个数字,题目中定义为Good Choice;也可能会出现循环的情况,就是无论怎么重复,只会出现某几个数,题目中定义为Bad Choice。题目给定step和mod,输...

vxiao_shen_longv的博客 274

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

HDU 1014 Uniform Generator

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1014水题:直接暴力破解,把所有的算一遍,看看0~mod-1之间的数字是否全部出现过#include<stdio.h> #define maxn 100000int main() { int step, mod; while(~scanf("%d%d", &step, &mod)) {

include_heqile的博客 370

HDU - 1014 - Uniform Generator

HDU 1014.Uniform Generator Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others) Problem DescriptionComputer simulations often require random numbers. One way to gen

在努力! 627

HDU ACM1014——Uniform Generator

Uniform Generator 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...

BarisGuo的博客 432

HDU1014 Uniform Generator

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1014这道题就是题目有点难懂,其实难度很小,就是产生伪随机数时给出的步长step和上限mod,判断下这两个值是否可以让产生的随机数均匀分布,所谓的均匀分布就是在mod步里能产生出0到mod-1这mod个数。Code highlighting produced by Act

1148

hdu 1014 Uniform Generator

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

老鼠 560

hdu1014 Uniform Generator

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 th

kingsirre的博客 312
上一篇: CodeForces 245C Game with Coins
下一篇: POJ 3268 Silver Cow Party(最短路dijkstra)
hellohelloC
博客等级 码龄12年 15粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值