D. Minimax Problem(二分+二进制)
5 seconds
512 megabytes
standard input
standard output
You are given nn arrays a1a1, a2a2, ..., anan; each array consists of exactly mm integers. We denote the yy-th element of the xx-th array as ax,yax,y.
You have to choose two arrays aiai and ajaj (1≤i,j≤n1≤i,j≤n, it is possible that i=ji=j). After that, you will obtain a new array bb consisting of mmintegers, such that for every k∈[1,m]k∈[1,m] bk=max(ai,k,aj,k)bk=max(ai,k,aj,k).
Your goal is to choose ii and jj so that the value of mink=1mbkmink=1mbk is maximum possible.
The first line contains two integers nn and mm (1≤n≤3⋅1051≤n≤3⋅105, 1≤m≤81≤m≤8) — the number of arrays and the number of elements in each array, respectively.
Then nn lines follow, the xx-th line contains the array axax represented by mm integers ax,1ax,1, ax,2ax,2, ..., ax,max,m (0≤ax,y≤1090≤ax,y≤109).
Print two integers ii and jj (1≤i,j≤n1≤i,j≤n, it is possible that i=ji=j) — the indices of the two arrays you have to choose so that the value of mink=1mbkmink=1mbk is maximum possible. If there are multiple answers, print any of them.
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
1 5
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string>
#define met(a,x) memset(a,x,sizeof(a));
#define rep(i,a,b) for(ll i = a;i <= b;i++)
#define bep(i,a,b) for(ll i = a;i >= b;i--)
#define lowbit(x) (x&(-x))
// #define mid ((l + r) >> 1)
// #define len (r - l + 1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define pb push_back
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b == ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
typedef unsigned long long ull;
typedef pair<int, int>Pi;
typedef pair<ll, pair<ll, ll> > Pii;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-);
const ll maxn = ;
const ll mod = ;
int a[maxn][];
int n, m,xx,yy;
int ok(int x) {
int vis[] = { };
rep(i,,n){
int now = ;
rep(j,,m){
if(a[i][j] >= x)now = now* + ;
else now = now*;
}
vis[now] = i;
}
rep(i, , ) {
rep(j, , ) {
if (vis[i] && vis[j] && ((i|j) == (( << m) - ))) {
xx = vis[i];
yy = vis[j];
return ;
}
}
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);
rep(i, , n) {
rep(j, , m) {
scanf("%d",&a[i][j]);
}
}
int l = , r = 1e9;
while (l <= r) {
int mid = (l + r) / ;
if (ok(mid)) l = mid + ;
else r = mid - ;
}
cout << xx << ' ' << yy << endl;
return ;
}
D. Minimax Problem(二分+二进制)的更多相关文章
- 【codeforces】Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理
题目链接 题目大意 有n个维度为m的向量,取其中两个进行合并,合并时每个维度取两者之间的较大者,得到的新的向量中,维度值最小者最大为多少 分析 首先最需要注意的是m的取值,m最大只有8 那么我们可以二 ...
- codeforces 1288D. Minimax Problem(二分)
链接:https://codeforces.com/contest/1288/problem/D D. Minimax Problem 题意:给定n个数组,长度为m,从n中数组挑选两个数组,两个数组中 ...
- D. Minimax Problem Codeforces 1288D binary_search+二进制
题目大意:n*m的矩阵中,找到两行数,可以形成两个一维数组,数组1的位置i和数组2的位置i去最大构成新数组b的元素b[i],最终目的要使数组b中最小的数尽可能的大 题解: m的范围是(1,8),比较小 ...
- HDU 4282 A very hard mathematic problem 二分
A very hard mathematic problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sh ...
- atcoder ARC092 D - Two Sequences 二分 & 二进制
今天生日捏,嘻嘻~ 题意:给定A B数组长度为n 求所有 (1<=i,j <=n ) a[i]+b[j] 的异或和. n <=200000 ai bi <=228 这题比赛没 ...
- POJ-2452 Sticks Problem 二分+RMQ
题目链接: https://cn.vjudge.net/problem/POJ-2452 题目大意: 给出一个数组a,求最大的j-i满足 i<j && a[i] ... a[j] ...
- Manthan, Codefest 16 B. A Trivial Problem 二分 数学
B. A Trivial Problem 题目连接: http://www.codeforces.com/contest/633/problem/B Description Mr. Santa ask ...
- D. Dasha and Very Difficult Problem 二分
http://codeforces.com/contest/761/problem/D c[i] = b[i] - a[i],而且b[]和a[]都属于[L, R] 现在给出a[i]原数组和c[i]的相 ...
- Codeforces 1288D - Minimax Problem
题目大意: 给定n个序列,每个序列元素个数严格相等于m 你需要找到两个序列a[i]和a[j],使其每个对应位置的元素取大后得到b序列 b[k]=max(a[i][k],a[j][k]) 且让b序列中 ...
随机推荐
- 对plotTree的解释
1.>>>a = 1/2/2 >>>a >>>0.25 2.def plotMidText(cntrPt,parentPt,txtString ...
- spark-submit脚本分析
执行任务 ./spark-submit \ --class cn.com.dtmobile.spark.DebugTest \ --master yarn \ --deploy-mode client ...
- 箭头函数arrow funtion
1.定义一个匿名函数常规语法: function (x) { return x * x; } 2.该函数使用箭头函数可以使用仅仅一行代码搞定! x => x * x 箭头函数相当于匿名函数,并且 ...
- js对象等号赋值的bug
var a = {n: 1}; var b = a; a.x = a = {n: 2}; console.log(a.x); console.log(b.x); 有道题是这样的,觉得很奇葩,分析一下 ...
- sudo 提权漏洞(CVE-2019-14287)复现 (10.16 第二十二天)
sudo是Linux系统命令,让普通账号以root身份去执行某些命令,比,安装软件.查看某些配置文件.关机.重启等操作,如果普通账号需要使用sudo需要修改配置文件/etc/sudoers,将sudo ...
- CodeForces - 706C Hard problem(dp+字符串)
题意:有n个字符串,只能将其逆转,不能交换位置,且已知逆转某字符串需要消耗的能量,问将这n个字符串按字典序从小到大排序所需消耗的最少能量. 分析:每个字符串要么逆转,要么不逆转,相邻两个字符串进行比较 ...
- MacOS Safari无响应卡死解决方法
之前也是用的好好的,突然一次进入一个网页就卡死了,强制退出,后面再重新进入Safari都会处于卡死状态,一直找不到解决方法,Safari也不能卸载重装,想着得等到更新系统或者重装系统,今天看到贴吧一个 ...
- ASP.NET Identity实现分布式Session,Docker+Nginx+Redis+ASP.NET CORE Identity
零.背景介绍 在学习ASP.NET CORE开发的过程中,身份认证是必须考虑的一项必要的组件.ASP.NET CORE Identity是由微软官方开发的一整套身份认证组件,兼具完整性和自由度.Doc ...
- java向python ,text文件动态传参或传值问题完美解决
由于业务需要对python文件进行参数传递,通过下面两个java方法完美解决此问题,我的思路是:首先我要先把上次写的参数删除,第二我要新的参数写到python文件中. 第一个方法解决了删除上次传递的参 ...
- Spring中的注解——@nullable和@notnull
@nullable和@nutNull 在写程序的时候你可以定义是否可为空指针.通过使用像@NotNull和@Nullable之类的annotation来声明一个方法是否是空指针安全的.现代的编译器.I ...