【codeforces】Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理
题目大意
有n个维度为m的向量,取其中两个进行合并,合并时每个维度取两者之间的较大者,得到的新的向量中,维度值最小者最大为多少
分析
首先最需要注意的是m的取值,m最大只有8
那么我们可以二分答案,对于每一个二分值,进行下面的操作
将整个矩阵的每一个元素,如果这个元素大于二分值,则变成1,反正则变成0
把每一个向量压缩为单个二进制数
这样我们最多只会得到\(2^8 = 256\)种不同的二进制数,然后暴力的遍历所有可能的二进制数的组合,得到是否满足当前二分值
AC code
#include <bits/stdc++.h>
using namespace std;
const int NUM = 3e5 + 100;
int data[NUM][10];
bool check(int value, int n, int m, pair<int, int> &ans) {
map<unsigned, int> s;
for (int i = 0; i < n; ++i) {
unsigned temp = 0;
for (int j = 0; j < m; ++j) {
temp <<= 1u;
temp |= data[i][j] > value;
}
s.insert({temp, i});
}
unsigned tar = -1u >> (sizeof(int) * 8 - m);
for (auto iter1 = s.begin(); iter1 != s.end(); ++iter1) {
for (auto iter2 = iter1; iter2 != s.end(); ++iter2) {
if ((iter1->first | iter2->first) == tar) {
ans.first = iter1->second;
ans.second = iter2->second;
return true;
}
}
}
return false;
}
void solve() {
int n, m;
cin >> n >> m;
int l = INT_MAX, r = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> data[i][j];
l = min(l, data[i][j]);
r = max(r, data[i][j]);
}
}
int mid, cnt = r - l;
pair<int, int> ans;
while (cnt > 0) {
int step = cnt / 2;
mid = l + step;
if (check(mid, n, m, ans)) {
l = mid + 1;
cnt -= step + 1;
} else
cnt /= 2;
}
cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef ACM_LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long long test_index_for_debug = 1;
char acm_local_for_debug;
while (cin >> acm_local_for_debug) {
cin.putback(acm_local_for_debug);
if (test_index_for_debug > 20) {
throw runtime_error("Check the stdin!!!");
}
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
}
#else
solve();
#endif
return 0;
}
【codeforces】Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理的更多相关文章
- D. Minimax Problem(二分+二进制)
D. Minimax Problem time limit per test 5 seconds memory limit per test 512 megabytes input standard ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...
- codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers
题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...
- codeforces Educational Codeforces Round 16-E(DP)
题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Educational Codeforces Round 15 C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- Redis: userd_memory使用超出maxmemory
Redis:userd_memory使用超出maxmemory 一.问题现象 2018.12.30 19:26分,收到Redis实例内存使用告警“内存使用率299%>=80%”,检查实例info ...
- 阿里投资Magic Leap 是美酒还是毒药?
Leap 是美酒还是毒药?" title="阿里投资Magic Leap 是美酒还是毒药?"> 土豪阿里又摊上"大事"了!但这次不是让人头痛的假 ...
- ckeditor 捕获键代码
<!--<script type="text/javascript"> var ctrlKey = false; var shiftKey = false; if ...
- LeetCode~报数(简单)
报数(简单) 题目描述: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1 11 21 1211 111221 1 被读作 "one 1" ( ...
- Maven项目中的packaging标签
<packaging>XXX</packaging> 项目的打包类型xxx:pom.jar.war.(packing默认是jar类型). pom是最简单的打包类型,pom 项目 ...
- OAuth 流程与发展总结 (1.0 => 1.0a => 2.0)
OAuth 流程与发展 (1.0 => 1.0a => 2.0) 概述 概述: 开放授权协议 作用: 允许第三方应用访问服务提供方中注册的终端用户的部分资源 下面是官方描述: [OAuth ...
- 使用node打造自己的命令行
一.实现一个简单的功能 二.环境 1.系统: window 10 2.编辑器: vscode 3.node版本: 8.7.0 三.开始玩 1.打开命令行,新建一个pa'ckage.json npm i ...
- localstorage浏览器储存
需求 a.html页面生成订单信息,b.html中调用. 通过不操作数据库,直接在浏览器自带的数据库中进行操作,当然主要是对Json数据的操作. a.html代码部分: <!--html--&g ...
- SQL数据库中的增删改查总结1
一.增:有2种方法 1.使用insert插入单行数据: 语法:insert [into]<表名> [列名] values <列值> 例:insert into Strdents ...
- notepad++ 快捷键运行python程序目录存在空格的问题
通常情况下 cmd /k (python.exe文件所在路径) "$(FULL_CURRENT_PATH)"&PAUSE&EXIT 就ok了,路径里有空格就不一样了 ...