C - Maximum of Maximums of Minimums(数学)
C - Maximum of Maximums of Minimums
You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get?
Definitions of subsegment and array splitting are given in notes.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105) — the size of the array a and the number of subsegments you have to split the array to.
The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109).
Output
Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments.
Example
5 2
1 2 3 4 5
5
5 1
-4 -5 -3 -2 -1
-5
Note
A subsegment [l, r] (l ≤ r) of array a is the sequence al, al + 1, ..., ar.
Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark).
In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result.
In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5
水题,关键是搞清楚题意,还有当k==2时,为什么是max(a[0], a[n-1]),为什么a[0],和a[n-1]一定是序列里的最小值????
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main()
{
int n,k;
int i,j;
int ans;
int mmax,mmin;
int a[];
mmax = -1e9-;
mmin = 1e9+;
scanf("%d %d",&n, &k);
for(i = ; i < n; i++)
{
scanf("%d",&a[i]);
}
if(k == )
{
for(i = ; i < n; i++)
{
mmin = min(a[i], mmin);
}
printf("%d\n",mmin);
}
else if(k == )
{
ans = max(a[], a[n-]);
printf("%d\n",ans);
}
else if(k >= )
{
for(i = ; i < n; i++)
{
mmax = max(a[i], mmax);
}
printf("%d\n",mmax);
}
return ;
}
C - Maximum of Maximums of Minimums(数学)的更多相关文章
- codeforces Round #440 B Maximum of Maximums of Minimums【思维/找规律】
B. Maximum of Maximums of Minimums time limit per test 1 second memory limit per test 256 megabytes ...
- Codeforces 872B:Maximum of Maximums of Minimums(思维)
B. Maximum of Maximums of Minimums You are given an array a1, a2, ..., an consisting of n integers, ...
- 【Codeforces Round #440 (Div. 2) B】Maximum of Maximums of Minimums
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] k=1的时候就是最小值, k=2的时候,暴力枚举分割点. k=3的时候,最大值肯定能被"独立出来",则直接输出最 ...
- Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
- Codeforces Contest 870 前三题KEY
A. Search for Pretty Integers: 题目传送门 题目大意:给定N和M个数,从前一个数列和后一个数列中各取一个数,求最小值,相同算一位数. 一道水题,读入A.B数组后枚举i.j ...
- Codeforces Round #440 (Div. 2) A,B,C
A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...
- ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers You are given two lists of non-zero digits. Let's call an integer pret ...
- MySQL 5.6 Reference Manual-14.6 InnoDB Table Management
14.6 InnoDB Table Management 14.6.1 Creating InnoDB Tables 14.6.2 Moving or Copying InnoDB Tables to ...
随机推荐
- spring与mybatis
- 刷题向》一道简单的思路题BZOJ1800(EASY+)
这道题其实并不难,主要原因是数据范围很小,当然数据如果大来也可以优化,但重点是在做的时候用的思路很通用, 所以本题是一道思想题(当然思想也不难) 标题里的“+”体现在一些边界处理中. 直接甩题目 De ...
- Nginx源码完全注释(8)ngx_errno.c
errno.h中的strerror(int errno)可以确定指定的errno的错误的提示信息.在 Nginx 中,将所有错误提示信息预先存储在一个数组里,而预先确定这个数组的大小,是在自动化脚本中 ...
- iOS倒计时
现在开发基本上都有发送验证码,倒计时,下面说一种 #import <UIKit/UIKit.h> @interface UIButton (CountDown) -(void)startT ...
- iOS中NSDate常用转换操作整合
//当前时间格式化, 例:YYYY-MM-dd-EEEE-HH:mm:ss + (NSString *)getCurrentDataWithDateFormate:(NSString *)format ...
- Oracle VM VirtualBox 部署CS devcloud2 开发环境
Setting up (VirtualBox) 1. Get the new DevCloud 2.0 virtual appliance. The new image was created usi ...
- Auto Control 002 自动控制的数学模型
2016-9-27 20:20:08 还需要进行修改和完善.先这种理论性的博客不太好写,请大家见谅. 在上一篇博客中,我们重点了解了关于自动控制原理的一些基本概念 以及一些相关的术语,以及能够分析控制 ...
- MapServer:地图发布工具
MapServer简介:https://baike.baidu.com/item/MapServer
- CAD&CG GDC 2018大会论文录用名单
Section 1 增强现实与图形学: 报告时间:2018-8-25 14:00-15:30 报告地点:会议室1 P000009 基于增强现实的产品质量信息传递方法 P000104 重彩画的风格转移 ...
- 编写高质量代码改善C#程序的157个建议——建议109:谨慎使用嵌套类
建议109:谨慎使用嵌套类 使用嵌套类的原则是:当某类型需要访问另一个类型的私有成员时,才将它实现为嵌套类.一个典型的例子是在实现集合时,要为集合实现迭代器,这时用到了嵌套类.代码如下所示: publ ...