题目链接

Problem Description

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

One day, Kblack is given an chessboard and he decides to plant flags on the chessboard where the position of each flag is described as a coordinate , which means that the flag is planted at the th line of the 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 in the generation,which equals to initially.When you call for a random number ranged from ,the generation will trans into .And then,it will return .

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

For each testcase,there is a single line contains 4 integers .

Then,you need to generate the flags' coordinates.

For ,firstly generate a random number in the range of .Then generate a random number in the range of .

You can also copy the following code and run "Init" to generate the x[],y[] (only for C++ players).

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);
}

(1≤T≤7),(1≤n,m≤1000000),(0≤k≤1000000),(0≤seed<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)

分析:

给你一个n*m的棋盘,然后在上面放置棋子,但是这些妻子的位置并不是要你自己输入的,而是随机产生的,然后根据题目中已经给出的函数计算出来的,我们要计算的就是该棋盘中有几行和几列没有放棋子。

看懂题觉得很简单,然而竟然一开始压根就没有看懂题目啥意思,感觉智商不够用了。

代码:

    #include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<map>
#include<string.h>
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 numr=0,numl=0;
bool row[1000001],line[1000001];
int n,m,k,seed;
int x[1000001],y[1000001]; void Init()
{
scanf("%d%d%d%d",&n,&m,&k,&seed);
memset(row,false,sizeof(row));
memset(line,false,sizeof(line));
numr=0;
numl=0;
_X=seed;
for (int i=1;i<=k;++i)
{
x[i]=get_rand(1,n);//生成的行坐标
y[i]=get_rand(1,m);//列坐标
if(row[x[i]]==false)//该行没有放过的话,就放一个,并且标记为已放过
{
numr++;
row[x[i]]=true;
}
if(line[y[i]]==false)//该列没有放过的话,就放一个,并且标记为已放过
{
numl++;
line[y[i]]=true; }
}
}
int main()
{
int N;
scanf("%d",&N);
while(N--)
{
Init();
printf("%d %d\n",n-numr,m-numl);
}
return 0;
}

最新文章

  1. String 与StringBuilder有什么区别
  2. 关于“windows无法自动将ip协议栈绑定到网络适配器”问题导致不能连上网的解决办法
  3. 实现gridview空白处的点击事件
  4. 真机在wifi下调试android程序
  5. JS高级程序设计2nd部分知识要点6
  6. android 点击edittext弹出软键盘,否则不弹
  7. saltstack远程操作WINDOWS的POWERSHELL脚本
  8. Jersey的异常处理
  9. mxnet运行时遇到问题及解决方法
  10. 升级旧Delphi应用转向支持手机的一个思路
  11. 图文详解ReSharper 8.1功能变化
  12. jQuery_第五章_事件和动画
  13. 洛谷3月月赛 R1 Step! ZERO to ONE
  14. Dynamics CRM2013 Server2012下部署ADFS和IFD遇到的问题No Organization were retrived
  15. PHP设计模式_工厂模式
  16. py使用笔记-pandas函数
  17. nginx日志分析 GoAccess
  18. 分享插件的使用加一个echart走数据
  19. sql知识收集
  20. python之系统命令

热门文章

  1. spring mvc4 找不到静态文件js/css/html 404
  2. 【转】Base64算法详解
  3. 在DbGrid中,不按下Ctrl,单击鼠标如何实现多选?谢谢
  4. ping不通的常见原因和解决办法
  5. MVC 中创建自己的异常处理
  6. 【bzoj5183】[Baltic2016]Park 离线+对偶图+并查集
  7. MySQL一主两从
  8. Astronauts UVALive - 3713(2-SAT)
  9. [CF1111E]Tree
  10. 已知UIScrollView放大后的Frame和放大之前的Frame计算放大的瞄点坐标