题目链接

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

HDU 5995 Kblack loves flag (模拟)的更多相关文章

  1. HDU 5995 Kblack loves flag ---BestCoder Round #90

    题目链接 用两个布尔数组分别维护每个行/列是否被插过旗帜,最后枚举每一行.列统计答案即可.空间复杂度O(n+m),时间复杂度O(n+m+k). #include <cstdio> #inc ...

  2. BestCoder Round #90 A.Kblack loves flag(随机数生成种子)

    A.Kblack loves flag [题目链接]A.Kblack loves flag [题目类型]水题 &题意: kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,k ...

  3. HDU 4876 ZCC loves cards(暴力剪枝)

    HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...

  4. hdu 4876 ZCC loves cards(暴力)

    题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...

  5. hdu 5274 Dylans loves tree(LCA + 线段树)

    Dylans loves tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  6. hdu 5266 pog loves szh III(lca + 线段树)

    I - pog loves szh III Time Limit:6000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I ...

  7. hdu 4873 ZCC Loves Intersection(大数+概率)

    pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...

  8. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  9. HDU 4873 ZCC Loves Intersection(可能性)

    HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...

随机推荐

  1. vue-cli配置axios,并基于axios进行后台请求函数封装

    文章https://www.cnblogs.com/XHappyness/p/7677153.html已经对axios配置进行了说明,后台请求时可直接this.$axios直接进行.这里的缺点是后端请 ...

  2. Java多线程 -yield用法

    前几天复习了一下多线程,发现有许多网上讲的都很抽象,所以,自己把网上的一些案例总结了一下! 一. Thread.yield( )方法: 使当前线程从执行状态(运行状态)变为可执行态(就绪状态).cpu ...

  3. Java多线程 -join用法

    阿里面试官问我这个问题,我仔细总结了一下: 参考:sleep.yield.wait.join的区别(阿里面试) 1. join()介绍 join() 定义在Thread.java中.join() 的作 ...

  4. shell脚本中调用其他脚本的三种方法

    方法一:使用 .     #. ./sub.sh 方法二:使用 source    #source ./sub.sh 方法三:使用 sh    #sh ./sub.sh 注意: 1.两个点之间,要有空 ...

  5. Android 混淆签名打包

    1.混淆文件 proguard-rules.pro # Add project specific ProGuard rules here. # By default, the flags in thi ...

  6. Linux进入单用户模式(passwd root修改密码)

    进入单用户模式——passwd root修改密码 1.在grub 页面输入a,进入修改内核模式 2.在内核的结尾“/”,输入空格,在输入single,回车 3.启动系统,进入单用户模式 4.Passw ...

  7. 移动端开发-viewport

    1.viewport viewport 即设备 屏幕上显示网页的区域.因为移动设备屏幕比较小,为了能让移动设备能够显示更多内容,默认设置的viewport 并不是屏幕真是像素点的宽度,一般为980px ...

  8. 【刷题】洛谷 P4143 采集矿石

    题目背景 ZRQ成功从坍塌的洞穴中逃了出来.终于,他看到了要研究的矿石.他想挑一些带回去完成任务. 题目来源:Zhang_RQ哦对了ZRQ就他,嗯 题目描述 ZRQ发现这里有 \(N\) 块排成一排的 ...

  9. redis的Pub/Sub功能

    Pub/Sub功能(即Publish,Subscribe)意思是发布及订阅功能.简单的理解就像我们订阅blog一样,不同的是,这里的客户端与server端采用长连接建立推送机制,一个客户端发布消息,可 ...

  10. Cisco Smart Install远程命令执行漏洞

    0x01前言 在Smart Install Client代码中发现了基于堆栈的缓冲区溢出漏洞,该漏洞攻击者无需身份验证登录即可远程执行任意代码.cisco Smart Install是一种“即插即用” ...