codeforces Round #440 B Maximum of Maximums of Minimums【思维/找规律】
1 second
256 megabytes
standard input
standard output
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.
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).
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.
5 2
1 2 3 4 5
5
5 1
-4 -5 -3 -2 -1
-5
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 ksequences (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个区间里的最小值。
【分析】:观察,发现最大化的值和k有关。
【代码】:
#include<bits/stdc++.h> using namespace std; int n,k;
const int maxn = 1e5+;
int a[maxn];
#define inf 0x3f3f3f3f
int main()
{
int mm,ma;
memset(a,,sizeof(a));
while(cin>>n>>k)
{
mm=inf;
ma=-inf;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
mm=min(mm,a[i]);
ma=max(ma,a[i]);
}
if(k==)
{
cout<<mm<<endl;
return ;
}
if(k>)//分割大于2时,最大化策略为总把最大值划为单独,就可以最大化结果刚好为最大值
{
cout<<ma<<endl;
return ;
}
if(k==)//分割为2个区间时,想要最大化,策略1 5 9 7 2/9 5 1 7 8可以试试,无论在哪里隔板,肯定符合两端的最大值。
{
cout<<max(a[],a[n-])<<endl;
}
}
return ;
}
codeforces Round #440 B Maximum of Maximums of Minimums【思维/找规律】的更多相关文章
- codeforces Round #440 C Maximum splitting【数学/素数与合数/思维/贪心】
C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #260 (Div. 2) A , B , C 标记,找规律 , dp
A. Laptops time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #493 (Div. 1) B. Roman Digits 打表找规律
题意: 我们在研究罗马数字.罗马数字只有4个字符,I,V,X,L分别代表1,5,10,100.一个罗马数字的值为该数字包含的字符代表数字的和,而与字符的顺序无关.例如XXXV=35,IXI=12. 现 ...
- Codeforces Round #440 (Div. 2)【A、B、C、E】
Codeforces Round #440 (Div. 2) codeforces 870 A. Search for Pretty Integers(水题) 题意:给两个数组,求一个最小的数包含两个 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...
- 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 ...
- 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 ...
- 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 #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
随机推荐
- 数据结构—队列(Queue)
队列的定义--Queue 队列是只允许在表的队尾插入,在表的队头进行删除.队列具有先进先出的特性(FIFO, First In First Out). 队列提供了下面的操作 q.empty() 如果队 ...
- 深入探讨Android异步精髓Handler
探索Android软键盘的疑难杂症 深入探讨Android异步精髓Handler 详解Android主流框架不可或缺的基石 站在源码的肩膀上全解Scroller工作机制 Android多分辨率适配框架 ...
- Js跑马灯效果 && 在Vue中使用
DEMO: <!DOCTYPE html><html> <head> <title>滚动播报</title> <meta charse ...
- 收藏一个漂亮的Flash焦点图切换
网上闲逛的时候发现一个Flash焦点图效果,跟喜欢,然后就下载回来,收集在这里,以便以后方便取用.这个Flash使用方法也是相当简单的,如果你喜欢,也可以从这里查看源代码下载. Flash 焦点图效果 ...
- rsync 同步
1./usr/bin/rsync -vzrtopg --progress --include "weibo-service-server" --exclude "/*& ...
- MyEclipse快捷键大全(转)1
Ctrl+1 快速修复(最经典的快捷键,就不用多说了) Ctrl+D: 删除当前行 Ctrl+Alt+↓ 复制当前行到下一行(复制增加) Ctrl+Alt+↑ 复制当前行到上一行(复制增加) Alt+ ...
- COGS2085 Asm.Def的一秒
时间限制:1 s 内存限制:256 MB [题目描述] “你们搞的这个导弹啊,excited!” Asm.Def通过数据链发送了算出的疑似目标位置,几分钟后,成群结队的巡航导弹从“无蛤”号头顶掠过 ...
- 【CF1027D】Mouse Hunt(拓扑排序,环)
题意:给定n个房间,有一只老鼠可能从其中的任意一个出现, 在第i个房间设置捕鼠夹的代价是a[i],若老鼠当前在i号房间则下一秒会移动到b[i]号, 问一定能抓住老鼠的最小的总代价 n<=2e5, ...
- Python爬虫学习 - day2 - 站点登陆
利用Python完成简单的站点登陆 最近学习到了爬虫,瞬时觉得很高大上,想取什么就取什么,感觉要上天.这里分享一个简单的登陆抽屉新热榜的教程(因为它不需要验证码,目前还没有学会图像识别.哈哈),供大家 ...
- 在linux下搭建wiki环境【转】
转自:http://blog.csdn.net/chy800/article/details/6906090 由于公司需要一个知识共享的系统,选择wiki来实现.经过准备决定使用Linux+xampp ...