【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 ...
随机推荐
- 关于排序原生js实现
内外排序的区别 排序可以分为两种:内排序和外排序.当数据量不算太大的时候,计算可以在内存中完成的排序称为内排序.当数据量特别大,计算的数据,需要分多次进入内存中进行计算的排序称之为外排序 插入排序 直 ...
- <pre>标签的使用
做做笔记.碰见了一个网站,显示代码的时候自带语法高亮,这很新鲜.它的代码被pre标签包裹,原本以为pre标签下的所有的内容会以文本原来的样式输出,特意查了查发现它依然支持html标签. 先来个菜鸟教程 ...
- 关于RN的热更新
写点关于RN的热更新和RN版本升级后的强制更新.以及优化白屏问题 在APPDelegate中加载RN,一般的加载方式是:RCTRootView *rootView= [[RCTRootView all ...
- NumPy的随机函数子库——numpy.random
NumPy的随机函数子库numpy.random 导入模块:import numpy as np 1.numpy.random.rand(d0,d1,...,dn) 生成一个shape为(d0,d1, ...
- numpy.random模块用法总结
from numpy import random numpy.random.uniform(low=0.0, high=1.0, size=None) 生出size个符合均分布的浮点数,取值范围为[l ...
- JavaScript 预解析机制
首先我们来看一段代码: <script> console.log(a); var a = 10; </script> 此时运行结果为 为什么会显示undefined呢?这就 ...
- python基础-基本概念
python概念介绍 python是一门动态解释型的强类型定义语言,创始人吉多·范罗苏姆(Guido van Rossum) #编译型语言 编译型:一次性将所有程序编译成二进制文件 缺点:开发效率低, ...
- k3s原理分析丨如何搞定k3s node注册失败问题
前 言 面向边缘的轻量级K8S发行版k3s于去年2月底发布后,备受关注,在发布后的10个月时间里,Github Star达11,000颗.于去年11月中旬已经GA.但正如你所知,没有一个产品是十全十美 ...
- Mybatis-Plus代码生成器使用详解
首先创建springboot的项目(创建步骤省略) 创建好项目后要配置maven依赖,附上pom.xml: <?xml version="1.0" encoding=&quo ...
- 全差分运算放大器ADA4930的分析(2)
前面解释了在ADA4930组成的单端转差分电路的输入电阻RIN的大小,可知当RF=RG=1KΩ的时候,RIN=1.33KΩ. 图1单端转差分电路 如图1所示,假设信号源为2V VPP的信号,信号源的内 ...