• D. Minimax Problem


    You are given n arrays a1, a2, ..., an; each array consists of exactly m integers. We denote the y-th element of the x-th array as ax,y.
    
    You have to choose two arrays ai and aj (1≤i,j≤n, it is possible that i=j). After that, you will obtain a new array b consisting of m integers, such that for every k∈[1,m] bk=max(ai,k,aj,k).
    
    Your goal is to choose i and j so that the value of mink=1mbk is maximum possible.
    
    Input
    The first line contains two integers n and m (1≤n≤3105, 1≤m≤8) — the number of arrays and the number of elements in each array, respectively.
    
    Then n lines follow, the x-th line contains the array ax represented by m integers ax,1, ax,2, ..., ax,m (0≤ax,y≤109).
    
    Output
    Print two integers i and j (1≤i,j≤n, it is possible that i=j) — the indices of the two arrays you have to choose so that the value of mink=1mbk is maximum possible. If there are multiple answers, print any of them.
    
    Example
    inputCopy
    6 5
    5 0 3 1 2
    1 8 9 1 3
    1 2 3 4 5
    9 1 0 3 7
    2 3 0 6 3
    6 4 1 7 0
    outputCopy
    1 5

    如何获得这个最小值的最大值,暴力必T,可以试着二分。

    而二分的check如何判断

    check(x)思路,把数组转化成二进制形式,如果当前为大于x,则改位二进制数为1,否则为零,最后的到的二进制数即可替代数组,且他最大为255

    然后暴力循环。

    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    #include<vector>
    #include<queue>
    #define ll long long
    const int inf=0x3f3f3f3f;
    using namespace std;
    const int N=3e5+5;
    int vis[260];
    int a[N][10];
    int n,m;
    int x,y;
    bool check(int key)
    {
        //printf("debug
    ");
        int t;
        memset(vis,0,sizeof vis);
        for(int i=1;i<=n;i++)
        {
            t=0;
            for(int j=1;j<=m;j++)
            {
                if(a[i][j]>=key)
                {
                    t|=1<<(j-1);
                }
            }
            //printf("%d
    ",t);
            vis[t]=i;
        }
        for(int i=0;i<=256;i++)
        {
            for(int j=0;j<=256;j++)
            {
                if(vis[i]&&vis[j]&&((i|j)==((1<<m)-1)))
                {
                    x=vis[i];
                    y=vis[j];
                    //printf("debug
    ");
                    return true;
                }
            }
        }
        return false;
    }
    int main()
    {
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        int l=0,r=1e9;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(check(mid))
            {
                l=mid+1;
            }
            else
                r=mid-1;
        }
        printf("%d %d
    ",x,y);
        return 0;
    }
    View Code
  • 相关阅读:
    Android SingleTask启动模式与Home键的问题
    Flutter Widget截图
    Flutter 以Dialog Activity形式展现
    Flutter Text或者RichText不换行的问题
    Adnroid提高效率之资源移动
    GO学习之 输入输出
    GO学习之 运算符
    GO学习之 值类型与引用类型
    GO学习之 指针
    GO学习之 变量与变量的基本数据类型
  • 原文地址:https://www.cnblogs.com/switch-waht/p/12197017.html
Copyright © 2020-2023  润新知