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 ...
随机推荐
- 技术基础 | Apache Cassandra 4.0基准测试
Apache Cassandra 4.0已经发布了Beta版,这是第一个支持JDK 11及更高JDK版本的Cassandra版本. 时延对于Apache Cassandra用户来说是个显而易见的关 ...
- Flask的“中间件”
特殊装饰器 from flask import Flask,render_template,request app = Flask(__name__) @app.before_request def ...
- Django 模型(数据库)-cmd下的操作
Django 模型是与数据库相关的,与数据库相关的代码一般写在 models.py 中,Django 支持 sqlite3, MySQL, PostgreSQL等数据库,只需要在settings.py ...
- 攻击JWT的一些方法
JWT安全隐患之绕过访问控制 https://mp.weixin.qq.com/s/xe8vOVhaysmgvxl-A3nkBA 记录一次JWT的越权渗透测试 https://mp.weixin.qq ...
- 陈思淼:阿里6个月重写Lazada,再造“淘宝”的技术总结
小结: 1. 所谓的中台技术,就是从 IDC,网络,机房,操作系统,中间件,数据库,算法平台,数据平台,计算平台,到业务平台,每一层都有清晰的定义和技术产品. 具体来看,首先,集团技术的分层和每层的产 ...
- pywin32 pywin32 docx文档转html页面 word doc docx 提取文字 图片 html 结构
https://blog.csdn.net/X21214054/article/details/78873338# python docx文档转html页面 - 程序猿tx - 博客园 https:/ ...
- Redis 学习笔记系列文章之 Redis 的安装与配置 (一)
1. 介绍 Redis is an open source (BSD licensed), in-memory data structure store, used as database, cach ...
- 阿里一面,给了几条SQL,问需要执行几次树搜索操作?
前言 有位朋友去阿里面试,他说面试官给了几条查询SQL,问:需要执行几次树搜索操作?我朋友当时是有点懵的,后来冷静思考,才发现就是考索引的几个基础知识点~~ 本文我们分九个索引知识点,一起来探讨一下. ...
- Grafana+Influxdb+Telegraf监控mysql
Grafana+Influxdb+Telegraf监控mysql 一.安装 1.1安装Grafana+influxdb+telegraf 1.2启动服务,添加开机启动 1.3查看grafana界面 二 ...
- 单体架构、SOA架构、微服务架构