题目描述

在麦克雷的面前有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. dubbo快速入门demo

    参考文章 https://blog.csdn.net/abcwanglinyong/article/details/81906027 该demo包含三个项目,分别是: 服务提供端项目:provider ...

  2. const关键字:终于拥有真正的常量声明语句

    本文首发于个人网站:const关键字:终于拥有真正的常量声明语句 你好,今天大叔想和你唠扯唠扯 ES6 新增的关键字 -- const.在说 const 关键字之前,大叔先和你唠唠大叔自己对 cons ...

  3. 低功耗降线性稳压器,24V转5V降压芯片

    PW2330开发了一种高效率的同步降压DC-DC变换器3A输出电流.PW2330在4.5V到30V的宽输入电压范围内工作集成主开关和同步开关,具有非常低的RDS(ON)以最小化传导 损失.PW2330 ...

  4. Building a high performance JSON parser

    Building a high performance JSON parser https://dave.cheney.net/high-performance-json.html

  5. Golang 性能优化实战

    小结: 1. 性能查看工具 pprof,trace 及压测工具 wrk 或其他压测工具的使用要比较了解. 代码逻辑层面的走读非常重要,要尽量避免无效逻辑. 对于 golang 自身库存在缺陷的,可以寻 ...

  6. Go Concurrency Patterns: Pipelines and cancellation

    https://blog.golang.org/pipelines Go Concurrency Patterns: Pipelines and cancellation Sameer Ajmani1 ...

  7.  Go is more about software engineering than programming language research.

    https://talks.golang.org/2012/splash.article Go at Google: Language Design in the Service of Softwar ...

  8. 服务器端IO模型的简单介绍及实现 阻塞 / 非阻塞 VS 同步 / 异步 内核实现的拷贝效率

    小结: 1.在多线程的基础上,可以考虑使用"线程池"或"连接池","线程池"旨在减少创建和销毁线程的频率,其维持一定合理数量的线程,并让空闲 ...

  9. 【c++小知识】static用法浅析

    一.前言 C++的关键字static分两种用法,在面向过程程序设计(c语言中的普通变量和函数)中的使用和在面向对象程序设计(c++中的类)中的使用 二.面向过程程序设计中的static(静态变量.静态 ...

  10. Java内存溢出处理

    在解决java内存溢出问题之前,需要对jvm(java虚拟机)的内存管理有一定的认识. jvm管理的内存大致包括三种不同类型的内存区域:Permanent Generation space(永久保存区 ...