HDU 5995 Kblack loves flag (模拟)
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 (模拟)的更多相关文章
- HDU 5995 Kblack loves flag ---BestCoder Round #90
题目链接 用两个布尔数组分别维护每个行/列是否被插过旗帜,最后枚举每一行.列统计答案即可.空间复杂度O(n+m),时间复杂度O(n+m+k). #include <cstdio> #inc ...
- BestCoder Round #90 A.Kblack loves flag(随机数生成种子)
A.Kblack loves flag [题目链接]A.Kblack loves flag [题目类型]水题 &题意: kblack喜欢旗帜(flag),他的口袋里有无穷无尽的旗帜. 某天,k ...
- HDU 4876 ZCC loves cards(暴力剪枝)
HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...
- hdu 4876 ZCC loves cards(暴力)
题目链接:hdu 4876 ZCC loves cards 题目大意:给出n,k,l,表示有n张牌,每张牌有值.选取当中k张排列成圈,然后在该圈上进行游戏,每次选取m(1≤m≤k)张连续的牌,取牌上值 ...
- hdu 5274 Dylans loves tree(LCA + 线段树)
Dylans loves tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- hdu 5266 pog loves szh III(lca + 线段树)
I - pog loves szh III Time Limit:6000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I ...
- hdu 4873 ZCC Loves Intersection(大数+概率)
pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 4873 ZCC Loves Intersection(可能性)
HDU 4873 ZCC Loves Intersection pid=4873" target="_blank" style="">题目链接 ...
随机推荐
- 2nd 四人小组项目的进一步分析
组长:林莉 组员:王东涵.宫丽君.胡丽娜 项目选题:车辆管理系统(附加相关员工管理) 项目期限:暂定十周 一.NABCD模型 N-Need 需求分析及相应功能设置 需求概述: 管理库中车辆信息.相关人 ...
- Java基于Tomcat Https keytool 自签证书
本文大部分内容系转载,原文地址:https://www.cnblogs.com/littleatp/p/5922362.html keytool 简介 keytool 是java 用于管理密钥和证书的 ...
- [历史百科]抗战时期兵团简介 From 百度知道
中央军委1948年11月1日和1949年1月15日两次关于统一全军组织和部队番号的训令,我军先后进行了整编.西北野战军改称第一野战军,司令员兼政治委员彭德怀,第一副司令员张宗逊,第二副司令员赵寿山,参 ...
- 【C++】C++的构造函数
构造函数是特殊的成员函数,只要创建类类型的对象,都要执行构造函数.构造函数的工作是保证每个对象的数据成员具有合适的初始值. class Sales_Item { public: //operation ...
- 【Python】Python基础教程系列目录
Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. 在现在的工作及开发当中,Python的使用越来越广泛,为了方便大家的学习,Linux大学 特推出了 <Python基 ...
- 【刷题】BZOJ 1030 [JSOI2007]文本生成器
Description JSOI交给队员ZYX一个任务,编制一个称之为"文本生成器"的电脑软件:该软件的使用者是一些低幼人群,他们现在使用的是GW文本生成器v6版.该软件可以随机生 ...
- 【JavaScript】简介、<Script>标签及基本概念
一.前言 时光荏苒,岁月匆匆.今年年初进入数据平台部门转型做Web平台.要想搞好前端肯定要学好JavaScript,于是准备抓上一俩本书从基础学起. 二.内容 简介 JavaScript是 ...
- BZOJ4152:[AMPPZ2014]The Captain——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4152 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1 ...
- BNU-2017.7.5排位赛3总结
链接:https://www.bnuoj.com/v3/contest_show.php?cid=9148#info A题 满足条件的只有(1,2,4),(1,2,6),(1,3,6),所以先满足4, ...
- libiop通讯流程和api讲解
上一篇讲到了libiop基本结构,这次根据libiop提供的test跟踪下消息和运行流程 void echo_server_test() { ; iop_base_t *); printf(" ...