题目描述

在麦克雷的面前有N个数,以及一个R*C的矩阵。现在他的任务是从N个数中取出 R*C 个,并填入这个矩阵中。矩阵每一行的法值为本行最大值与最小值的差,而整个矩阵的法值为每一行的法值的最大值。现在,麦克雷想知道矩阵的最小法值是多少。

输入

输入共两行。

第一行是三个整数:n,r,c。(r, c <= 104, r * c <= n <= 106

第二行是 n 个整数 Pi。(0 < pi <= 109)

输出

输出一个整数,即满足条件的最小的法值。

样例输入

7 2 3
170 205 225 190 260 225 160

样例输出

30

可以说是最大值最小化的模板题了,但是比赛的时候没写对。
赛后想了想还是对这类题理解不深。
二分枚举答案,只要找出满足答案的一种情况就行,不需要硬找出最佳的满足情况。所以这题里面直接for循环就好,不需要搜出所有r个的c的情况。

附ac代码:
 1 #include <bits/stdc++.h>
2 using namespace std;
3 const int maxn = 1e6;
4 const int inf = 0x3f3f3f3f;
5 int nu[maxn];
6 int dis[maxn];
7 int n, r, c;
8 int fun(int minn)
9 {
10 int rr = 0;
11 int i = c;
12 while(i <= n)
13 {
14 if(dis[i] <= minn)
15 {
16 ++rr;
17 if(rr == r) return 1;
18 i += c;
19 }
20 else ++i;
21 }
22 return 0;
23 }
24 int main() {
25
26 scanf("%d %d %d", &n, &r, &c);
27 for(int i = 1; i <= n; ++i)
28 {
29 scanf("%d", &nu[i]);
30 }
31 sort(nu + 1, nu + 1 + n);
32 for(int i = c; i <= n; ++i)
33 {
34 dis[i] = nu[i] - nu[i - c + 1];
35 // printf("%d ", dis[i]);
36 }
37 int lt = 0, rt = inf;
38 while(lt <= rt)
39 {
40 int mid = lt + (rt - lt) / 2;
41 // printf("%d\n", mid);
42 if(fun(mid)) rt = mid - 1;
43 else lt = mid + 1;
44 }
45 printf("%d\n", lt);
46 return 0;
47 }

zzuli-2259 matrix的更多相关文章

  1. angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation

    今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:

  2. Pramp mock interview (4th practice): Matrix Spiral Print

    March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...

  3. Atitit Data Matrix dm码的原理与特点

    Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...

  4. Android笔记——Matrix

    转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...

  5. 通过Matrix进行二维图形仿射变换

    Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...

  6. [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  7. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  8. [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  9. [LeetCode] Search a 2D Matrix 搜索一个二维矩阵

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  10. [LeetCode] Set Matrix Zeroes 矩阵赋零

    Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. click ...

随机推荐

  1. Java-Servlet知识总结

    目录 Servlet概述 为什么要学习Servlet 什么是 Servlet 工作流程 生命周期 处理请求的方法 HttpServletRequest 和 HttpServletResponse Ht ...

  2. 缓存淘汰算法 LRU 和 LFU

    LRU (Least Recently Used), 即最近最少使用用算法,是一种常见的 Cache 页面置换算法,有利于提高 Cache 命中率. LRU 的算法思想:对于每个页面,记录该页面自上一 ...

  3. AQS之ReentrantReadWriteLock写锁

    用法 1.1 定义一个安全的list集合 public class LockDemo { ArrayList<Integer> arrayList = new ArrayList<& ...

  4. 特斯拉Toolbox诊断检测仪工具Tesla诊断电脑 Tesla Toolbox

    Tesla特斯拉Toolbox诊断工具Tesla诊断电脑检测仪 Tesla Toolbox, Tesla Toolbox Diagnostic Tester.Language: English,Deu ...

  5. 推荐大家去撸60元的阿里云ACA DevOps认证

    要试题的右边扫码支付10元,私聊博客哈,说出你微信号,留下邮箱,发你邮箱Pdf文件,这么便宜拿证!!

  6. C#高级编程第11版 - 第五章 索引

    [1]5.1 泛型概述 1.通过泛型,你可以创建独立于特定类型(contained types)以外的方法和类,而不用为不同类型编写多份同样功能的代码,你只需要创建一个方法或者类. 2.泛型类使用泛型 ...

  7. 什么是 MVC 模式

    概述 MVC,即 Model 模型.View 视图,及 Controller 控制器. View:视图,为用高糊提供使用界面,与用户直接进行交互. Model:模型,承载数据,并对用户提交请求进行计算 ...

  8. http 和 https 有何区别?如何灵活使用?

    http是HTTP协议运行在TCP之上.所有传输的内容都是明文,客户端和服务器端都无法验证对方的身份. https是HTTP运行在SSL/TLS之上,SSL/TLS运行在TCP之上.所有传输的内容都经 ...

  9. 网络流 - dinic + 当前弧优化【代码】

    这是初学网络流的时候从<算法竞赛进阶指南>抄下来的一份代码,自己理解的也不是很透彻. 注意,边要从 \(1\) 开始计,不然直接 \(xor\) 运算的话取反边会直接炸掉. #includ ...

  10. LOJ10019生日蛋糕

    Mr.W 要制作一个体积为 N*π 的 M 层生日蛋糕,每层都是一个圆柱体. 设从下往上数第 i 蛋糕是半径为 R_i,高度为 H_i 的圆柱.当 i<M 时,要求 R_i>R_{i+1} ...