Kblack loves flags, so he has infinite flags in his pocket.
One day, Kblack is given an n∗mn∗m chessboard and he decides to plant flags on the chessboard where the position of each flag is described as a coordinate (x,y)(x,y), which means that the flag is planted at the xxth line of the yyth 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 n∗mn∗m chessboard and he decides to plant flags on the chessboard where the position of each flag is described as a coordinate (x,y)(x,y), which means that the flag is planted at the xxth line of the yyth 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.
We have a private variable xx in the generation,which equals to seedseed initially.When you call for a random number ranged from [l,r][l,r],the generation will trans xx into (50268147x+6082187) mod 100000007(50268147x+6082187) mod 100000007.And then,it will return x mod (r−l+1)+lx mod (r−l+1)+l.
The first line contains a single integer TT refers to the number of testcases.
For each testcase,there is a single line contains 4 integers n,m,k,seedn,m,k,seed.
Then,you need to generate the kk flags' coordinates.
For i=1⋯ki=1⋯k,firstly generate a random number in the range of [1,n][1,n].Then generate a random number in the range of [1,m][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 x10000011000001,y10000011000001;
void Init(){
scanf("%d%d%d%d",&n,&m,&k,&seed);
_X=seed;
for (int i=1;i<=k;++i)
xii=get_rand(1,n),
yii=get_rand(1,m);
}
</pre>
(1≤T≤7)(1≤T≤7),(1≤n,m≤1000000)(1≤n,m≤1000000),(0≤k≤1000000)(0≤k≤1000000),(0≤seed<100000007)(0≤seed<100000007)
2 4 2 3 233 3 4 4 2333
2 1
1 0
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)$
题意:K黑很喜欢旗子,随身携带很多旗子
某天,kblack得到了一个n*m的方格棋盘,他决定把kk面旗帜插到棋盘上。
每面旗帜的位置都由一个整数对(x,y)来描述,表示该旗帜被插在了第x行第y列。
插完旗帜后,kblack突然对那些没有插过旗帜的行和列很不满,于是他想知道,有多少行、列上所有格子都没有被插过旗帜。
kblack还要撩妹(程序员撩什么妹,有代码和右手就够了),于是就把这个问题丢给了你,请你帮他解决
一道水题不多说 上代码。
#include<cstring> #include<iostream> #include<stdio.h> using namespace std; const int _K=50268147,_B=6082187,_P=100000007; int _X,x[1000005],y[1000005]; inline int get_rand(int _l,int _r){ _X=((long long)_K*_X+_B)%_P; return _X%(_r-_l+1)+_l; } int main() { int t,i; scanf("%d",&t); while(t--) { memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); int n,m,k,seed,cnt1=0,cnt2=0,a,b; scanf("%d%d%d%d",&n,&m,&k,&seed); _X=seed; while(k--) { a=get_rand(1,n); b=get_rand(1,m); x[a]=1; y[b]=1; } for(i=1;i<=n;i++) { if(x[i]==0)cnt1++; } for(i=1;i<=m;i++) { if(y[i]==0)cnt2++; } printf("%d %d\n",cnt1,cnt2); } return 0; }