hdoj1014

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

Uniform Generator

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


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
 

Source
 

Recommend
JGShining
#include<stdio.h>

int gcd(int a,int b){
    if(a<b)
        return gcd(b,a);
    else if(a%b==0)
        return b;
    else return gcd(b,a%b);
}

int main(void){
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF){
        if(gcd(a,b)-1)
            printf("%10d%10d    Bad Choice\n\n",a,b);
        else
            printf("%10d%10d    Good Choice\n\n",a,b);
    }
    return 0;
}


ACM速刷水题汇总 ACM速刷水题,分类汇总,附答案。 立即下载

相关推荐

PDN设计

作者:AirCity 2020.2.6 Aircity007@sina.com 本文所有权归作者Aircity所有 PDN设计的目的是降低电源纹波水平,减小电压跌落。我们通常要求LDO的文波水平是30mV,DCDC是50mV,超过这个就需要PDN设计。 PDN设计的方法是用不同的容值,合适的总电容量,降低电源平面与地平面之间的交流阻抗,确定容值总量和电容大小的过程,就是PDN设计过程。 为什么需...

AirCity123的博客 4147

POJ 1597 Uniform Generator

循环群周期

scorpiocj的专栏 764

macOS 27下PlayCover“没有权限打开”的完整修复指南

macOS系统通过Gatekeeper、TCC(透明、同意与控制)和安全启动等机制,对第三方应用进行层层校验,以防范恶意代码。这些机制会检查应用的隔离属性、签名状态以及所需系统权限,当任一环节不满足时,就会出现“没有权限打开”的提示。对于开发者工具或未上架App Store的开源软件,这类拦截尤为常见。尤其在macOS 27上,系统进一步收紧了绕过策略,导致PlayCover等工具无法正常启动。本文以PlayCover为例,详细解析权限链路上的三道关卡,并给出清除隔离属性、调整SIP状态、重置TCC记录等完

weixin_32612263的博客 745

1175: ACM"水题"

题目DescriptionACM中把一种题称作“水题”,顾名思义就是题目很水,很简单。为了促进提高大伙的编程兴趣, zjahstu决定贯彻“没有最水,只有更水”的原则。 现在给定两个数a和b, 计算[a,b]之间整数的和。(当a=b=0时候表示输入结束,不必处理) Input1 100 1 10 99 100 0 0 Output5050 55 199Sample Inp

光光的小屋 626

详细Ubuntu 22.04 配置最新UR机械臂仿真环境(ros2-humble, ur-sim, ur-ros2-driver)

使用ubuntu22.04.01和ur-sim, ur-driver进行ur机械臂的仿真

verloge的博客 1万+

【博客汇总】UV打印机博客汇总

UV平板机博客汇总

Print World的专栏 1743

ACM水题

2017.03.185个数求最值描述 设计一个从5个整数中取最小数和最大数的程序 输入 输入只有一组测试数据,为五个不大于1万的正整数 输出 输出两个数,第一个为这五个数中的最小值,第二个为这五个数中的最大值,两个数字以空格格开。 样例输入1 2 3 4 5样例输出1 5代码实现#include <iostream> using namespace std; int main(){

u012241729的专栏 480

阿里云大模型 ACP 认证教材内容突变?这些改动藏着通关密码,不看亏大!

【摘要】核心章节大换血,安全合规融入实战场景,大模型微调用数学深度解析,部署章节带来阿里云产品对比实战攻略,甚至整章内容被替换成藏满学习彩蛋的行业趋势指南。这些改动不仅重塑考试重点,更暗藏官方命题风向——安全合规考场景方案,微调原理考几何解析,部署设计考分析框架。无论你是数学小白还是部署新手,这篇攻略都将带你吃透变动逻辑,附赠急救包和考点清单,帮你抓住这些“隐形加分项”,速来解锁通关秘籍!

davidkorhenn的博客 1755

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

【华为2021校招】笔试题【通用硬件】

时间:2020/07/15 19:00 时长:60min 题型:40单选+5多选 难度:中等 考察范围:模电、数电、SI、EMC、电源、微机原理、计算机网络、材料

Jkcia的博客 4万+

LTC3783 LED驱动控制器设计与效率优化详解

开关电源控制器是现代LED照明的核心器件,通过电流模式控制实现高效能量转换。其核心原理是通过采样电阻检测负载电流,配合误差放大器形成闭环调节,在汽车电子、显示背光等场景中确保±3%的电流精度。LTC3783作为典型代表,集成升压/降压-升压多拓扑支持,配合PWM调光技术可实现3000:1的无色偏调光范围。在工程实践中,需重点考量功率电感选型、MOSFET开关损耗与热管理设计,例如在38W功率方案中采用10μH/5A电感和4.5mΩ MOSFET可达成95%效率。该方案特别适用于需要应对9-36V宽输入电压波

weixin_36231030的博客 400

HDOJ1014 Uniform Generator 【三种解法(暴力+互质)】

HDOJ1014 题目 思路 简单来说,题目的意思是给定STEP和MOD,能够把0到MOD-1的数都产生一次的就是Good Choice,否则就是Bad Choice。 1.暴力求解:定义一个seed数组从seed[0]依次往后计算。定义一个布尔型isChange数组,计算出seed[i]的值时,对应的isChange[seed[i]]就记为true。最后如果isChange数组中的值都为true...

hfut橘生淮南的博客 411

YALMIP介绍及怎么在Matlab中加YALMIP、SDPT3

目录YALMIP简介怎么在Matlab中加YALMIP?1. 创建决策变量:2. 添加约束:3. 参数配置4. 求解怎么在MatlabR2019a中加YALMIP?1.下载工具包2.放置工具包3.添加路径4.测试安装结果怎么在MatlabR2019a中加SDPT3? YALMIP简介 怎么在Matlab中加YALMIP? yalmip是一位“集大成者”,它不仅自己包含基本的线性规划求解算法,比如linprog(线性规划)、bintprog(二值线性规划)、bnb(分支界定算法)等,他还提供了对cpl

m0_51431440的博客 2万+

HDOJ 1014

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34234823的博客 186

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

hdoj-1014-C

原题链接:hdoj1014 好像用互质能解,留坑待填 #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; int main() { int step; int mod; int i; int temp; while(scanf("%d%d",&amp;step,&amp;mod)!=EOF){ ...

你有我备注吗的博客 219

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

HDU 1014

题很长,看起来挺唬人的,其实是纸老虎。 大意就是给出两个数,STEP , MOD 然后根据给出的递推公式算一下 0~ mod-1之间的数是否都有出现过,如果都出现了,那就是Good 否则bad 初始种子不只是0,可以取0~mod-1之间的所有数,所以要用一个循环检验所有情况   //Problem:hdu1014 //Data:2011/10/30 #include #include

程书画的 BLOG 2344

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

hdoj 1014

//AC 1 #include #include using namespace std; int main(void) {     int step, mod,cur,n;     const char*a[] = { "Good Choice","Bad Choice" };     while (cin >> step >> mod)     {         n

WuchangI的博客 359

HDOJ 1014 模拟

题目大意:给出两个数 ,s,m,按照题目中的要求计算生成的随机数列,判断是否生成了0~m-1这m个数列,若是则是好的选择,否则是坏的选择。 算法思想; 用一个标记flag[MAXN]来记录前0~m-1是否生成,同时用num记录数列的长度,循环判断当前的数是否先前生成过,若没有则标记,否及判断num是否等于m,若等则是一个好的选择,不等则不是一个好选择。输出时s,m均占10个字节有队齐,字符串从

找到生活的 节奏&&驱动力 1002

【HDOJ】1014 -> Uniform Generator

心得:         本题可转化为证明step与mod互质,因为若step与mod不互质,则seed[gcd(step,mod)]=0。 代码: #include using namespace std; int gcd(int a,int b){ if(!b) return a; return gcd(b,a%b); } int main() {

一个程序猿的BLOG 669

hdoj1014简单题

#include #include #include using namespace std; int main(){ int m, n; int seed; while(cin>>m>>n){ int count[100005] = {0}; seed = 0; count[0] = 1; for(int i = 1; i < n; i++){

liuzhushiqiang的专栏 597

HDOJ 1014 Uniform Generator

HDACM1014 此题做法:用布尔数组的下标值来表示0~mod-1,通过其布尔值来判断一个循环是否结束,如过布尔数组的每个布尔值都为true则Good Choice,否则Bad Choiceimport java.util.Scanner;public class Main{ public static void main(String[] args) { Scanne

whale blog 184

hdoj 1014 Uniform Generator

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

世界很大 660

hdoj1014 互质

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

Ferryman__的博客 283
上一篇: hdoj1013
下一篇: hdoj1015
lulining
博客等级 码龄15年 8粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值