zoukankan      html  css  js  c++  java
  • Kblack loves flag


    title: Kblack loves flag
    tags: [acm,杭电]

    题目链接

    Kblack loves flag

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 265    Accepted Submission(s): 190

    Problem Description

    Kblack loves flags, so he has infinite flags in his pocket.
    One day, Kblack is given an n∗m chessboard and he decides to plant flags on the chessboard where the position of each flag is described as a coordinate (x,y), which means that the flag is planted at the xth line of the yth 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 x in the generation,which equals to seed initially.When you call for a random number ranged from [l,r],the generation will trans x into (50268147x+6082187) mod 100000007.And then,it will return x mod (r−l+1)+l.
    The first line contains a single integer T refers to the number of testcases.
    For each testcase,there is a single line contains 4 integers n,m,k,seed.
    Then,you need to generate the k flags' coordinates.
    For i=1⋯k,firstly generate a random number in the range of [1,n].Then generate a random number in the range of [1,m].
    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)$
    

    题意

    真的没有读懂题目啥意思,,,

    很简单的一道题目,有一个棋盘,和一些棋子,现在给你出棋子的坐标,让你求出还有多少行,多少列没有放过棋子。但是,这些棋子的坐标不是直接输入的,而是通过一个随机函数来生成的,这个函数呢,人家又给你了,直接复制过来就行了。输入格式: 棋盘的行数和列数,以及棋子的个数,和生成棋子坐标的种子。

    代码

    #include <iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    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 n,m,k,seed;
    int rowN=0,lineN=0;
    
    int x[1000001],y[1000001];
    bool row[1000001]= {false};
    bool line[1000001]= {false};
    void Init()
    {
        scanf("%d%d%d%d",&n,&m,&k,&seed);
        rowN=0,lineN=0;
        memset(row,false,sizeof(row));
        memset(line,false,sizeof(line));
        _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)
            {
                row[x[i]]=true;
                rowN++;
            }
            if(line[y[i]]==false)
            {
                line[y[i]]=true;
                lineN++;
            }
        }
    }
    int main()
    {
    
        int t;
        cin>>t;
        while(t--)
        {
            Init();
            cout<<n-rowN<<" "<<m-lineN<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    Linux下DNS服务器搭建详解
    Oracle 数据泵使用详解--精华版
    Oracle 数据泵详解
    数据泵
    Oracle11g数据库导入Oracle10g数据库操作笔记
    DNS服务器
    spring mvc发送请求404,不能进入处理方法,也不报错
    CentOS设置默认启动命令行(不启动图形界面)
    SQL Server 排序的时候使 null 值排在最后
    Git教程
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/6710382.html
Copyright © 2011-2022 走看看