杭电oj 1014
2015-12-08 21:30
387 查看
题目
Total Submission(s): 22744 Accepted Submission(s): 8944
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
Each line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
由于这题要求输出格式,在这里我给大家普及一下输出的格式问题
C++有两种方法控制格式输出:1、用格式控制符;2、用流对象的成员函数 格式控制符。
1 、I/O流常用控制符:
使用控制符时,在程序开头加投文件#include <iomanip>
dec 设置基数为10
hex 设置基数为16
oct 设置基数为8
setfill(c) 设置填充字符c
setprecision(n) 设置显示小数精度为n位
setw(n) 设置域宽为n个字符
setiosflags(ios::fixed) 固定的浮点显示
setiosflags(ios::scientific) 指数表示
setiosflags(ios::left) 左对齐
setiosflags(ios::right) 右对齐
setiosflags(ios::skipws) 忽略前导空白
setiosflags(ios::uppercase) 16进制数大写输出
setiosflags(ios::lowercase) 16进制小写输出
2、用流对象的成员函数 格式控制符:
可以不使用#include<iomanip>的
cout.precision()设置小数点后精确度,
cout.width()设置宽度,
cout.setf()设置显示格式,比如
cout.setf(ios::left)左对齐
cout.setf(ios::showpoint)不管是否有小数位,显示小数点
cout.fill();不足宽度则填充,如cout.fill('0');
如这次周赛1002,如果使用COUT在输出前要这样设置一下。
cout.precision(6);
cout.width(8);
cout.setf(ios::left);
cout.setf(ios::showpoint);
cout.fill('0');
下面我再来说这个题,这个题就是求a 、b是不是互质。若能看出来这个,这题就是非常简单了
下面贴出我得ac代码
Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22744 Accepted Submission(s): 8944
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
Each line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
3 5 15 20 63923 99999
[align=left]Sample Output[/align]
3 5 Good Choice 15 20 Bad Choice 63923 99999 Good Choice
由于这题要求输出格式,在这里我给大家普及一下输出的格式问题
C++有两种方法控制格式输出:1、用格式控制符;2、用流对象的成员函数 格式控制符。
1 、I/O流常用控制符:
使用控制符时,在程序开头加投文件#include <iomanip>
dec 设置基数为10
hex 设置基数为16
oct 设置基数为8
setfill(c) 设置填充字符c
setprecision(n) 设置显示小数精度为n位
setw(n) 设置域宽为n个字符
setiosflags(ios::fixed) 固定的浮点显示
setiosflags(ios::scientific) 指数表示
setiosflags(ios::left) 左对齐
setiosflags(ios::right) 右对齐
setiosflags(ios::skipws) 忽略前导空白
setiosflags(ios::uppercase) 16进制数大写输出
setiosflags(ios::lowercase) 16进制小写输出
2、用流对象的成员函数 格式控制符:
可以不使用#include<iomanip>的
cout.precision()设置小数点后精确度,
cout.width()设置宽度,
cout.setf()设置显示格式,比如
cout.setf(ios::left)左对齐
cout.setf(ios::showpoint)不管是否有小数位,显示小数点
cout.fill();不足宽度则填充,如cout.fill('0');
如这次周赛1002,如果使用COUT在输出前要这样设置一下。
cout.precision(6);
cout.width(8);
cout.setf(ios::left);
cout.setf(ios::showpoint);
cout.fill('0');
下面我再来说这个题,这个题就是求a 、b是不是互质。若能看出来这个,这题就是非常简单了
下面贴出我得ac代码
#include <iostream> #include <iomanip> using namespace std; //hdu-oj-1014 //判断输入的两个数是否互质,若互质则good choice //否则bad choice bool gcd(int a,int b) { if(a%b==0) { if(b==1) return true; else return false; } else return gcd(b,a%b); } int main() { int a,b; while(cin>>b>>a) { cout<<setw(10)<<std::fixed<<b<<setw(10)<<std::fixed<<a<<" "; if(gcd(a,b)) cout<<"Good Choice"<<endl; else cout<<"Bad Choice"<<endl; cout<<endl; } return 0; }
相关文章推荐
- Dropout中隐层节点的忽略比例与DAE中加噪比例参数的区别
- POJ 1830 (高斯消元)
- STM32库函数(3):库文件stm32f10x_flash.c内的函数
- BZOJ1295: [SCOI2009]最长距离
- Lucene中的 Query对象
- Exchange Server 2013 运维系列——解决多域名同用户的配置问题
- [leetcode] 199. Binary Tree Right Side View
- hdu2082找单词(母函数)
- 【Android游戏开发十四】深入Animation,在SurfaceView中照样使用Android—Tween Animation!
- PTC_Mathcad Prime3.0 矩阵的运算
- uva-10921
- ROS在多机器人上的运行
- 2015年12月8日日志
- js判断MAC地址
- lucene-SpanFirstQuery 和SpanNearQuery 跨度查询
- The Secrets of Oracle Row Chaining and Migration
- 【Android游戏开发十三】(保存游戏数据 [下文])详解SQLite存储方式,并把SQLite的数据库文件存储在SD卡中!!!
- 黑马程序员——异常
- SimpleSprite,SlicedSprite,Tiled Sprite,FilledSprite的区别
- ——基于方法的权限控制