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;
        }
    
  • 相关阅读:
    DS4700磁盘阵列的控制器微码升级操作记录(收录百度文库)
    Android 解决布局无法对齐的情况
    android 模仿大众点评团购卷列表多余3条时折叠,点击时显示剩余全部的功能
    android 解决ScrollView中的子布局不能够填充整个ScrollView的情况。
    Android在代码中设置控件的drawableLeft,drawableRight,drawableTop,drawableBottom。
    android RadioGroup中设置selector后出现多个别选中的RadioButton的解决办法
    Android 动态的给Button、TextView、ImageView等控件设置了background后,再设置padding属性时该属性不起作用
    Android Universal Image Loader java.io.FileNotFoundException: http:/xxx/lxx/xxxx.jpg
    Android2.3系统 自定义的PopupWindow在实例化时报空指针异常
    android精品开源项目整理
  • 原文地址:https://www.cnblogs.com/cmmdc/p/6729558.html
Copyright © 2011-2022 走看看