• 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;
        }
    
  • 相关阅读:
    使用NoSQL可视化管理工具时报错The GuidRepresentation for the reader is CSharpLegacy
    git和github连接权限(这是一个简便方法,不是很安全,建议大家还是用ssh解决)
    python模块的使用
    利用python抓取页面数据
    利用递归解决“汉诺塔的移动”问题(使用python来做的,其它语言也行)
    mysql中利用show profile很直观的看到查询缓存的作用。
    MySQL中show profiles的开启
    浅谈依赖注入
    使用laraval框架和前端完成restful风格的请求对接(这里只是讨论restful的概念)
    利用composer安装laraval
  • 原文地址:https://www.cnblogs.com/cmmdc/p/6729558.html
Copyright © 2020-2023  润新知