zzuli-2259 matrix
题目描述
在麦克雷的面前有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的更多相关文章
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- 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 ...
- Atitit Data Matrix dm码的原理与特点
Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...
- Android笔记——Matrix
转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...
- 通过Matrix进行二维图形仿射变换
Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- [Cerc2005]Knights of the Round Table
题目描述 有n个骑士经常举行圆桌会议,商讨大事.每次圆桌会议至少有3个骑士参加,且相互憎恨的骑士不能坐在圆桌的相邻位置.如果发生意见分歧,则需要举手表决,因此参加会议的骑士数目必须是大于1的奇数,以防 ...
- Lakehouse: 统一数据仓库和高级分析的新一代开放平台
1. 摘要 数仓架构在未来一段时间内会逐渐消亡,会被一种新的Lakehouse架构取代,该架构主要有如下特性 基于开放的数据格式,如Parquet: 机器学习和数据科学将被作为头等公民支持: 提供卓越 ...
- MariaDB(selec的使用)
--查询基本使用 -- 查询所有列 --select * from 表名 select * from students; --一定条件查询 select * from students whe ...
- 路由协议-RIP协议
一.路由协议的发展历程和分类 距离矢量路由协议--听信"谣言",使用跳数作为度量值,最大16(0-15)跳:RIP 链路状态路由协议--"地图"路由协议:OSP ...
- vfd-cloud——一个适合练习上手的云存储网盘springboot项目(开发中)
vfd-cloud 一个基于SpringBoot的云存储网盘项目,适合练手学习SpringBoot,用到的技术栈列到了下面.支持用户的注册登陆及修改密码,利用邮箱进行验证.支持 ...
- 回归测试_百度百科 https://baike.baidu.com/item/%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95
回归测试_百度百科https://baike.baidu.com/item/%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95
- get uuid
https://wx2.qq.com/?&lang=zh_CN /** * 启动二维码登录 */ function doQrcodeLogin() { loginFactory.getUUID ...
- Nagle's algorithm 封包 网络游戏协议封包需注意点 封包挂
w41字节的数据包只有1字节的可用信息.以减少数据包发送量来提高TCP/IP网络性能. https://en.wikipedia.org/wiki/Nagle's_algorithm https:// ...
- Asp.netCore 3.1控制器属性注入and异步事务Aop by AutoFac
Aspect Oriented Programming(AOP)是较为热门的一个话题.AOP,国内我们都习惯称之为:面向切面编程 下面直接code 干货展示:(一般人我还不告诉,嘻嘻) 1:导入相关的 ...
- 配置《Orange's一个操作系统的实现》环境心得
<Orange>这本书开篇第一章就做了一个实例,编写了一段引导扇区的代码,但是引导介质仍然采用了已被淘汰多年的软盘.在经历了两天的痛苦查找后终于找到了最方便的解决办法,在此做一下记录,希望 ...