产生随机数

F.A.Q
Hand In Hand
Online Acmers
Forum | Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
      C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests 
    DIY | Web-DIY beta
Recent Contests

Kblack loves flag

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 76    Accepted Submission(s): 52


Problem Description
Kblack loves flags, so he has infinite flags in his pocket.

One day, Kblack is given an  nm  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.
 

Input
You should generate the input data in your programme.

We have a private variable  x  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 (rl+1)+l .

The first line contains a single integer  T  refers to the number of testcases.

For each testcase,there is a single line contains 4 integers  n,m,k,seed .

Then,you need to generate the  k  flags' coordinates.

For  i=1k ,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>

(1T7) , (1n,m1000000) , (0k1000000) , (0seed<100000007)
 

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
      
      
2 4 2 3 233 3 4 4 2333
 

Sample Output
      
      
2 1 1 0
Hint
the flags in the first case:$\left(4,2\right)$,$\left(1,2\right)$,$\left(1,2\right)$ the flags in the second case:$\left(2,1 \right)$,$\left(2,3\right)$,$\left(3,4\right)$,$\left(3,2\right)$
 

#include<cstdio>
#include<cstring>
#include<algorithm>
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],vx[1000006],vy[1000006];
void Init(){
	int num1=0,num2=0;
	scanf("%d%d%d%d",&n,&m,&k,&seed);
	_X=seed;
	memset(vx,0,sizeof(vx));memset(vy,0,sizeof(vy));
	for (int i=1;i<=k;++i){
		x[i]=get_rand(1,n);
		if(!vx[x[i]]){
			num1++;vx[x[i]]=1;
		}
		y[i]=get_rand(1,m);//产生随机点
		if(!vy[y[i]]){
			num2++;vy[y[i]]=1;
		}
	}
	printf("%d %d\n",n-num1,m-num2);	 	
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		Init();
	}
	
	return 0;
}


Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5998  5997  5996  5994  5993 
 
Statistic |  Submit |  Discuss |  Note
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值