HDU 5995 生成随机数然后统计--简单题
来源:互联网 发布:淘宝全部平台 编辑:程序博客网 时间:2024/06/06 00:48
Kblack loves flag
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 120 Accepted Submission(s): 93
Problem Description
Kblack loves flags, so he has infinite flags in his pocket.
One day, Kblack is given ann∗m chessboard and he decides to plant flags on the chessboard where the position of each flag is described as a coordinate (x,y) , which means that the flag is planted at the x th line of the y th row.
After planting the flags, Kblack feels sorry for those lines and rows that have no flags planted on, so he would like to know that how many lines and rows there are that have no flags planted on.
Well, Kblack, unlike you, has a date tonight, so he leaves the problem to you. please resolve the problem for him.
One day, Kblack is given an
After planting the flags, Kblack feels sorry for those lines and rows that have no flags planted on, so he would like to know that how many lines and rows there are that have no flags planted on.
Well, Kblack, unlike you, has a date tonight, so he leaves the problem to you. please resolve the problem for him.
Input
You should generate the input data in your programme.
We have a private variablex in the generation,which equals to seed initially.When you call for a random number ranged from [l,r] ,the generation will trans x into (50268147x+6082187) mod 100000007 .And then,it will return x mod (r−l+1)+l .
The first line contains a single integerT refers to the number of testcases.
For each testcase,there is a single line contains 4 integersn,m,k,seed .
Then,you need to generate thek flags' coordinates.
Fori=1⋯k ,firstly generate a random number in the range of [1,n] .Then generate a random number in the range of [1,m] .
You can also copy the following code and run "Init" to generate the x[],y[] (only for C++ players).
<pre>
const int _K=50268147,_B=6082187,_P=100000007;
int _X;
inline int get_rand(int _l,int _r){
_X=((long long)_K*_X+_B)%_P;
return _X%(_r-_l+1)+_l;
}
int n,m,k,seed;
int x[1000001],y[1000001];
void Init(){
scanf("%d%d%d%d",&n,&m,&k,&seed);
_X=seed;
for (int i=1;i<=k;++i)
x[i]=get_rand(1,n),
y[i]=get_rand(1,m);
}
</pre>
(1≤T≤7) ,(1≤n,m≤1000000) ,(0≤k≤1000000) ,(0≤seed<100000007)
We have a private variable
The first line contains a single integer
For each testcase,there is a single line contains 4 integers
Then,you need to generate the
For
You can also copy the following code and run "Init" to generate the x[],y[] (only for C++ players).
<pre>
const int _K=50268147,_B=6082187,_P=100000007;
int _X;
inline int get_rand(int _l,int _r){
_X=((long long)_K*_X+_B)%_P;
return _X%(_r-_l+1)+_l;
}
int n,m,k,seed;
int x[1000001],y[1000001];
void Init(){
scanf("%d%d%d%d",&n,&m,&k,&seed);
_X=seed;
for (int i=1;i<=k;++i)
x[i]=get_rand(1,n),
y[i]=get_rand(1,m);
}
</pre>
Output
For each testcase,print a single line contained two integers,which respectively represent the number of lines and rows that have no flags planted.
Sample Input
24 2 3 2333 4 4 2333
#include <iostream>#include <cstring>#include <string>using namespace std;const int _K = 50268147, _B = 6082187, _P = 100000007;int _X;inline int get_rand(int _l, int _r) {_X = ((long long)_K*_X + _B) % _P;return _X % (_r - _l + 1) + _l;}int n, m, k, seed;int x[1000006], y[1000006];void Init() {scanf("%d%d%d%d", &n, &m, &k, &seed);_X = seed;for (int i = 1; i <= k; ++i)x[i] = get_rand(1, n),y[i] = get_rand(1, m);}const int maxn = 1e6 + 5;int row_a[maxn];int column_a[maxn];int main(){int t;scanf("%d", &t);while (t--){memset(column_a, 0, sizeof(column_a));memset(row_a, 0, sizeof(row_a));int row = 0;int column = 0;Init();for (int i = 1; i <= k; i++){row_a[x[i]] = 1;column_a[y[i]] = 1;}for (int i = 1; i <= n; i++)if (!row_a[i])row++;for (int i = 1; i <= m; i++)if (!column_a[i])column++;printf("%d %d\n", row, column);}return 0;}
0 0
- HDU 5995 生成随机数然后统计--简单题
- 简单的随机数生成
- sql生成6为随机数,然后加密实现
- sql生成6为随机数,然后加密实现
- (2)生成随机数,打印并统计
- vb.net生成随机数,并且统计生成的个数
- 统计随机数
- 简单的生成不重复随机数
- QT实现简单滚动随机数生成程序
- php生成随机数,简单高效的方法
- python:numpy数组运算、排序、统计、随机数生成
- Python numpy随机数生成和数学统计运算[转]
- 数组应用实例(生成并打印随机数和统计随机数的分布)
- 【随机数】生成随机数模板
- 生成随机数
- 随机数生成
- 随机数生成
- 生成随机数
- linux 下安装redis
- kernel与文件系统通信
- test13
- Android利用jsoup爬虫爬网页数据(二)
- 生成器(Generators)
- HDU 5995 生成随机数然后统计--简单题
- session和cookie
- SSL/TLS相关知识点罗列
- 每次读《Spring源码深度解析》都有新收获
- CentOS 6.3下配置iSCSI网络存储
- linux下redis的安装配置测试
- AtomicInteger的并发处理,Volatile修饰的成员变量
- 爬虫
- HashMap与ConcurrentHashMap的区别