zoukankan      html  css  js  c++  java
  • 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 ight),left(1,2 ight),left(1,2 ight)

    the flags in the second case:left(2,1 ight),left(2,3 ight),left(3,4 ight),left(3,2 ight)

    分析:

    给你一个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-numr,m-numl);
        	} 
         return 0;
        }
    
  • 相关阅读:
    利用IDE自动生成Logger变量
    浏览器跨域请求
    linux shell 跟踪网站变动
    linux shell 查找网站中无效的链接
    linux shell 网页相册生成器
    Shell帮你掌管上千台服务(多线程)
    Ansible小实例
    Shell监控公网IP-变化邮件报警
    ffmpeg顺时针或逆时针旋转视频90,180度
    Download youtube videos with subtitles using youtube-dl
  • 原文地址:https://www.cnblogs.com/cmmdc/p/6729558.html
Copyright © 2011-2022 走看看