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≤3?105, 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
5
0 3 1 2
8 9 1 3
2 3 4 5
1 0 3 7
3 0 6 3
4 1 7 0
outputCopy
5
思路:最小值最大化問題,絕大概率是二分。但是二分之后的judge環節怎么弄呢?這就是本題的出彩之處。我們將每一個數組中的大于等于mid的位置設置為1,否則就設置為0。這樣我們進行或操作,這樣出來的就是取最大值操作了。這樣如果兩兩相或,如果各個位上都是1,就代表著當前的mid就是最小值,然后不斷的二分,就可以找到最優解了。
代碼如下:
努力加油a啊,(o)/~
總結
以上是生活随笔為你收集整理的Minimax Problem(二分+二进制状态压缩)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Two Arrays(DP递推)
- 下一篇: NEKO's Maze Game(思维)