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序列中 ...
随机推荐
- Node.js NPM 教程
NPM是Node.js的包(或模块)管理器,是Node.js应用程序开发的核心. www.npmjs.com上有海量的Node.js包,供免费下载使用. 当安装Node.js时,NPM程序会被同时安装 ...
- 算法实战(六)Z 字形变换
一.前言 之前因为第五题最长回文字符串需要使用到dp解法,所以我花了很长的时间来研究dp(因为每天又要上班,加上这段时间事情比较多,所以花了三个星期才搞定),好不容易算入了个门,有兴趣的同学可以看看我 ...
- mysql多表关联更新
update 表A inner join 表B on 表A.关联字段 = 表B.关联字段 set 表a.待更新字段01 = 表B.字段01 , 表a.待更新字段021 = 表B.字段02 where ...
- 【剑指Offer】面试题11. 旋转数组的最小数字
题目 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如,数组 [3,4,5,1,2] 为 [1,2,3,4,5] 的一个 ...
- 21 ~ express ~ 前台内容分类展示
一,前台 , views/main/index.html ,通过get传送给后台 思路 : 将栏目ID 传递给后台,后台根据 栏目的ID 返回相应的数据 {% if category == '' ...
- java课程之团队开发冲刺阶段2.7
昨日总结: 1.完整实现课前闹钟提醒功能 遇到的困难: 1.没有遇到大的问题,细节地方没有处理好出现了一下小的情况 今天的任务: 1.实现对课程查询的完整实现 当日总结: 1.以前是使用二级联动下拉框 ...
- Java TCP发送与接收
IP地址?端口号?主机名? 什么是Socket? 什么是UDP? 什么是TCP? UDP和TCP区别? 以上问题请自行百度,有标准解释,此处不再赘述,直接上干货! 实例: 发送端: public cl ...
- Essay写作关键:严谨的逻辑关系
一篇好的文章并不是句子的机械堆砌,而是一个有机整体,句子和句子之间是存在严谨的逻辑关系的,要注意句子和句子之间,段落和段落之间的衔接和连贯(Coherence and Cohesion). 要写出逻辑 ...
- VUE学习(一)——使用npm安装项目
npm是node.js自带的功能 Node.js 安装配置 本章节我们将向大家介绍在 Windows 和 Linux 上安装 Node.js 的方法. 本安装教程以 Node.js v4.4.3 LT ...
- git push 现有代码到一个新的分支
git push origin HEAD:task/xxx-test-local git push的一般形式为 git push <远程主机名> <本地分支名> <远程 ...