题目链接

题目大意

有n个维度为m的向量,取其中两个进行合并,合并时每个维度取两者之间的较大者,得到的新的向量中,维度值最小者最大为多少

分析

首先最需要注意的是m的取值,m最大只有8

那么我们可以二分答案,对于每一个二分值,进行下面的操作

将整个矩阵的每一个元素,如果这个元素大于二分值,则变成1,反正则变成0

把每一个向量压缩为单个二进制数

这样我们最多只会得到\(2^8 = 256\)种不同的二进制数,然后暴力的遍历所有可能的二进制数的组合,得到是否满足当前二分值

AC code

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int NUM = 3e5 + 100;
  4. int data[NUM][10];
  5. bool check(int value, int n, int m, pair<int, int> &ans) {
  6. map<unsigned, int> s;
  7. for (int i = 0; i < n; ++i) {
  8. unsigned temp = 0;
  9. for (int j = 0; j < m; ++j) {
  10. temp <<= 1u;
  11. temp |= data[i][j] > value;
  12. }
  13. s.insert({temp, i});
  14. }
  15. unsigned tar = -1u >> (sizeof(int) * 8 - m);
  16. for (auto iter1 = s.begin(); iter1 != s.end(); ++iter1) {
  17. for (auto iter2 = iter1; iter2 != s.end(); ++iter2) {
  18. if ((iter1->first | iter2->first) == tar) {
  19. ans.first = iter1->second;
  20. ans.second = iter2->second;
  21. return true;
  22. }
  23. }
  24. }
  25. return false;
  26. }
  27. void solve() {
  28. int n, m;
  29. cin >> n >> m;
  30. int l = INT_MAX, r = 0;
  31. for (int i = 0; i < n; ++i) {
  32. for (int j = 0; j < m; ++j) {
  33. cin >> data[i][j];
  34. l = min(l, data[i][j]);
  35. r = max(r, data[i][j]);
  36. }
  37. }
  38. int mid, cnt = r - l;
  39. pair<int, int> ans;
  40. while (cnt > 0) {
  41. int step = cnt / 2;
  42. mid = l + step;
  43. if (check(mid, n, m, ans)) {
  44. l = mid + 1;
  45. cnt -= step + 1;
  46. } else
  47. cnt /= 2;
  48. }
  49. cout << ans.first + 1 << " " << ans.second + 1 << endl;
  50. }
  51. signed main() {
  52. ios_base::sync_with_stdio(false);
  53. cin.tie(nullptr);
  54. cout.tie(nullptr);
  55. #ifdef ACM_LOCAL
  56. freopen("in.txt", "r", stdin);
  57. freopen("out.txt", "w", stdout);
  58. long long test_index_for_debug = 1;
  59. char acm_local_for_debug;
  60. while (cin >> acm_local_for_debug) {
  61. cin.putback(acm_local_for_debug);
  62. if (test_index_for_debug > 20) {
  63. throw runtime_error("Check the stdin!!!");
  64. }
  65. auto start_clock_for_debug = clock();
  66. solve();
  67. auto end_clock_for_debug = clock();
  68. cout << "Test " << test_index_for_debug << " successful" << endl;
  69. cerr << "Test " << test_index_for_debug++ << " Run Time: "
  70. << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
  71. cout << "--------------------------------------------------" << endl;
  72. }
  73. #else
  74. solve();
  75. #endif
  76. return 0;
  77. }

【codeforces】Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理的更多相关文章

  1. D. Minimax Problem(二分+二进制)

    D. Minimax Problem time limit per test 5 seconds memory limit per test 512 megabytes input standard ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  6. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. /lib64/libc.so.6: version `GLIBC_2.18' not found报错解决

    今日安装一区块链服务时报错:/lib64/libc.so.6: version `GLIBC_2.18' not found,检查后现有的glibc版本是2.17,然后参考https://www.ji ...

  2. 15.uboot study 串口初始化

    3. 串口初始化 4. 代码实现 关于串口 对于嵌入式设备的开发,刚开始好多设备都无法使用,由于无法获得程序的运行状态,调试程序需要花费好多时间和精力,因此串口对于嵌入式程序的调试的作用显而易见,当串 ...

  3. Dizcuz站点部署-包教会

      Dizcuz站点部署-包教会-有需要请联系小编! 小编微信号:wvqusrtg

  4. Golang/Python/PHP带你彻底学会gRPC

    目录 一.gRPC是什么? 二.Protocol Buffers是什么? 三.需求:开发健身房服务 四.最佳实践 Golang 1. 安装protoc工具 2. 安装protoc-gen-go 3. ...

  5. PHP压缩文件夹 php

    $path = PUBLIC_DIR.'/images/'; //待压缩文件夹父目录 $zipPath = PUBLIC_DIR.'/images_zip/'; //压缩文件保存目录 !is_dir( ...

  6. Flutter保持页面状态AutomaticKeepAliveClientMixin

    使用bottomNavigationBar切换底部tab,再切换回来就会丢失之前的状态(重新渲染列表,丢失滚动条位置). 解决方法 使用 AutomaticKeepAliveClientMixin 重 ...

  7. 无刷新上传图片,ajax 和 iframe

    iframe 上传 upload.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...

  8. Apache Tomcat 文件包含漏洞(CVE-2020-1938)

    2月20日,国家信息安全漏洞共享平台(CNVD)发布了Apache Tomcat文件包含漏洞(CNVD-2020-10487/CVE-2020-1938).该漏洞是由于Tomcat AJP协议存在缺陷 ...

  9. PHP把图片存入数据库(非路径)【待测试】

    大部分人的图片上传都是保存一个路径到数据库,这样在插入时确实快,也符合web的特点,但是在删除时就很麻烦,需要找到文件并删除,该代码能够把代码直接存入数据库,删除时一并删除.请注意:这样的话数据库大小 ...

  10. Java集合04——fail-fast&fail-safe 详解

    在前几个回合中,我们已经详细了解过了 Java 集合中的List.Set 和 Map,对这部分内容感兴趣的朋友可以关注我的公众号「Java面典」了解.今天我们将为各位介绍集合的失败机制--fail-f ...