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

转载于:https://www.cnblogs.com/cmmdc/p/6729558.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值