日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Minimax Problem(二分+二进制状态压缩)

發布時間:2023/12/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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就是最小值,然后不斷的二分,就可以找到最優解了。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;const int maxx=3e5+100; int a[maxx][10]; int vis[maxx]; int n,m;inline bool check(int mid,int &x,int &y) {memset(vis,0,sizeof(vis));for(int i=1;i<=n;i++){int cc=0;for(int j=1;j<=m;j++) if(a[i][j]>=mid) cc|=(1<<(j-1));vis[cc]=i;}for(int i=0;i<=255;i++)//由于最大就是8位,所以最大是255。{for(int j=0;j<=255;j++){if(vis[i]&&vis[j]&&(i|j)==(1<<m)-1){x=vis[i];y=vis[j];return 1;}}}return 0; } 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=1000000000;int x,y;while(l<=r){int mid=l+r>>1;if(check(mid,x,y)) l=mid+1;else r=mid-1;}cout<<x<<" "<<y<<endl;return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Minimax Problem(二分+二进制状态压缩)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。