首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >HDOJ 1014

HDOJ 1014

作者头像
用户1154259
发布于 2018-01-17 06:54:49
发布于 2018-01-17 06:54:49
49100
代码可运行
举报
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Uniform Generator

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


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值,在出现重复的值时就推出循环,然后调用allOnes函数来判断下这mod个值出现的次数是否都是1,如果不是就是bad

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 1 #include<iostream>
 2 #include<string>
 3 #include<iomanip>
 4 using namespace std;
 5  
 6 int p[100000];
 7  
 8 bool allOnes(int mod){
 9     for(int i=0;i<mod;i++)
10         if(p[i]==0 || p[i]>1)
11             return false;
12     return true;
13 }
14  
15 int main()
16 {
17     int step,mod;
18     while(cin>>step>>mod)
19     {
20  
21         memset(p,0,sizeof(p));
22         for(int i=0;p[0]==0||i!=0;i=(i+step)%mod)
23             p[i]++;
24         cout<<setiosflags(ios::right)<<setw(10)<<step;
25         cout<<setiosflags(ios::right)<<setw(10)<<mod;
26         if(allOnes(mod))
27             cout<<setw(4)<<""<<"Good Choice\n"<<endl;
28         else
29             cout<<setw(4)<<""<<"Bad Choice\n"<<endl;
30     }
31     return 0;
32 }

源自:http://www.cnblogs.com/fgfgfffg/archive/2012/01/12/2320944.html

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2012-10-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
HDOJ 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
谙忆
2021/01/21
3000
HDU 1014 Uniform Generator【GCD,水】
Uniform Generator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29336    Accepted Submission(s): 11694 Problem Description Computer simulations often require random numbers. One way to generate
Angel_Kitty
2018/04/09
6590
➡诡异的51代码⬅
www.radford.edu/ibarland/Manifestoes/whyC++isBad.shtml
zhangrelay
2021/12/02
5110
【量化精品】通过LSTM神经网络进行时序预测针对股票市场(附Python源码)
阅读原文 Neural Networks these days are the “go to” thing when talking about new fads in machine learning. As such, there’s a plethora of courses and tutorials out there on the basic vanilla neural nets, from simple tutorials to complex articles describing t
量化投资与机器学习微信公众号
2018/01/29
1.7K0
【量化精品】通过LSTM神经网络进行时序预测针对股票市场(附Python源码)
HDOJ 1335 Basically Speaking(进制转换)
Problem Description The Really Neato Calculator Company, Inc. has recently hired your team to help design their Super Neato Model I calculator. As a computer scientist you suggested to the company that it would be neato if this new calculator could convert among number bases. The company thought this was a stupendous idea and has asked your team to come up with the prototype program for doing base conversion. The project manager of the Super Neato Model I calculator has informed you that the calculator will have the following neato features: It will have a 7-digit display.
谙忆
2021/01/21
3620
ICOM6045 Topic 1 Cryptography
ICOM6045 Fundamentals of E-Commerce Security Topic 1 Cryptography Definition Process of transforming information to make it unreadable to anyone except those possessing the key Purpose Data confidentiality Transpositions/Permutations An encryption in which
pseudoyu
2023/04/11
3050
HDOJ 1323 Perfection(简单题)
Problem Description From the article Number Theory in the 1994 Microsoft Encarta: “If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not 1/-1, b is called a proper divisor of a. Even integers, which include 0, are multiples of 2, for example, -4, 0, 2, 10; an odd integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant.” Given a number, determine if it is perfect, abundant, or deficient.
谙忆
2021/01/21
3140
torch、(二) Generators
class torch._C.Generator(device='cpu') → Generator
狼啸风云
2019/09/25
1.1K0
Python基础练习100题 ( 71
这十道题的代码在我的github上,如果大家想看一下每道题的输出结果,可以点击以下链接下载:
py3study
2020/01/03
5520
python: random模块
  在numpy 和 tensorflow 中有 相同功能 的实现, 见 《tensorflow: Constants, Sequences, and Random Values》 。
JNingWei
2018/09/28
6460
Golang math/rand 源码剖析&避坑指南
本文以type rand struct 为切入点,看下 Go 伪随机数的实现原理。
恋喵大鲤鱼
2021/12/06
1.9K0
浅析SkipList跳跃表原理及代码实现
SkipList在leveldb以及lucence中都广为使用,是比较高效的数据结构。由于它的代码以及原理实现的简单性,更为人们所接受。我们首先看看SkipList的定义,为什么叫跳跃表?
sunsky
2020/08/20
7080
HDOJ 1312 (POJ 1979) Red and Black
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles.
谙忆
2021/01/19
3740
(数据科学学习手札03)Python与R在随机数生成上的异同
随机数的使用是很多算法的关键步骤,例如蒙特卡洛法、遗传算法中的轮盘赌法的过程,因此对于任意一种语言,掌握其各类型随机数生成的方法至关重要,Python与R在随机数底层生成上都依靠梅森旋转(twiste
Feffery
2018/04/17
1.1K0
C++(STL):22 ---序列式容器queue使用
queue是队列,特点是先进先出,后进后出,你可以理解为数据结构里的队列模型,他只允许你访问 queue<T> 容器适配器的第一个和最后一个元素。只能在容器的末尾添加新元素,只能从头部移除元素。 许多程序都使用了 queue 容器。queue 容器可以用来表示超市的结账队列或服务器上等待执行的数据库事务队列。对于任何需要用 FIFO 准则处理的序列来说,使用 queue 容器适配器都是好的选择。 图 1 展示了一个 queue 容器及其一些基本操作:
用户3479834
2021/02/03
1K0
C++(STL):22 ---序列式容器queue使用
C++学生选课系统 【含 代码】
本系统的用户分为普通用户和管理员两类,其中普通用户包括教师和学生。普通用户只能对自己的信息进行查询与修改,管理员则拥有所有功能权限。
全栈程序员站长
2022/11/04
2.3K0
C++学生选课系统 【含 代码】
Matlab 没有 randint,Matlab_learning_4(rand randn randint函数 )「建议收藏」
1>、RAND:Uniformly distributed random numbers.
全栈程序员站长
2022/07/31
5200
Python基础练习100题 ( 61
这十道题的代码在我的github上,如果大家想看一下每道题的输出结果,可以点击以下链接下载:
py3study
2020/01/03
5780
Python 数据科学实用指南
本指南探讨了允许你使用 Python 执行数据分析的最佳实践和基础知识。在本指南中,你将学习如何使用 Jupyter notebook 和 Python 库(如 Pandas , Matplotlib 和 Numpy )轻松、透明地探索和分析数据集。
iOSDevLog
2022/01/20
1.9K0
Python 数据科学实用指南
torch、(三) Random sampling
Sets the seed for generating random numbers to a non-deterministic random number. Returns a 64 bit number used to seed the RNG.
狼啸风云
2019/09/25
2K0
相关推荐
HDOJ 1014 Uniform Generator(公约数问题)
更多 >
领券
一站式MCP教程库,解锁AI应用新玩法
涵盖代码开发、场景应用、自动测试全流程,助你从零构建专属AI助手
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档