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 ...
随机推荐
- 基于Asp.Net Core 5.0依赖Quartz.Net框架编写的任务调度web管理平台
源码地址: https://github.com/246850/Calamus.TaskScheduler 演示地址:http://47.101.47.193:1063/ 1.Quartz.NET框架 ...
- 【Azure App Service For Container】创建ASP.NET Core Blazor项目并打包为Linux镜像发布到Azure应用服务
欢迎使用 Blazor!Blazor 是一个使用 .NET 生成交互式客户端 Web UI 的框架: 使用 C# 代替 JavaScript 来创建信息丰富的交互式 UI. 共享使用 .NET 编写的 ...
- CSS响应式布局学习笔记(多种方法解决响应式问题)
在做web开发的工作中,会遇到需要我给页面根据设计的要求,进行响应式布局,这里跟大家分享下我对于响应式布局的解决方法: 我主要利用的是CSS3 媒体查询,即media queries,可以针对不同的媒 ...
- 【AtCoder Beginner Contest 181】A~F题解
越学越菜系列 于2020.11.2,我绿了(错乱) A - Heavy Rotation 签到题,奇数Black,偶数White. code: #include<bits/stdc++.h> ...
- Redis 核心篇:唯快不破的秘密
天下武功,无坚不摧,唯快不破! 学习一个技术,通常只接触了零散的技术点,没有在脑海里建立一个完整的知识框架和架构体系,没有系统观.这样会很吃力,而且会出现一看好像自己会,过后就忘记,一脸懵逼. 跟着「 ...
- 并发编程之fork/join(分而治之)
1.什么是分而治之 分而治之就是将一个大任务层层拆分成一个个的小任务,直到不可拆分,拆分依据定义的阈值划分任务规模. fork/join通过fork将大任务拆分成小任务,在将小任务的结果join汇总 ...
- ryu安装
$ python3 -V Python 3.7.2 $ git clone https://github.com/faucetsdn/ryu.git $ cd ryu $ sudo pip3 inst ...
- .NET并发编程-函数式编程
本系列学习在.NET中的并发并行编程模式,实战技巧 函数式编程 和面向过程编程POP(procedure oriented Programming)面向对象编程OOP(object oriented ...
- 【题解】洛谷P3119 Grass Cownoisseur G
题面:洛谷P3119 Grass Cownoisseur G 本人最近在熟悉Tarjan的题,刷了几道蓝题后,我飘了 趾高气扬地点开这道紫题,我一瞅: 哎呦!这不是分层图吗? 突然就更飘了~~~ 用时 ...
- Mark基本语法
Markdown语法 1. 标题 样式的标题在行的开头使用1-6个#,对应于标题级别1-6.例如: 2.引用 在引用中再嵌套一个引用(在用">"的段落中使用"> ...