Codeforces 872 B Maximum of Maximums of Minimums
来源:互联网 发布:php txt教程下载 编辑:程序博客网 时间:2024/06/16 19:51
题目地址
题意:给你一个序列,然后让你把这个序列正好分割为k个子序列,每个子序列都选出一个最小值,然后求这些最小值的最大值为多少。
思路:这题就是考细节的,我在比赛中被hack了两次,然后最后一次hack还是在比赛结束以后的重测中。言归正传,我们可以发现存在以下的三种情况:
- m==1,这时候因为只能选1个子序列就是原序列了,所以就是输出最小值了。
- m==2,这时候我们可以发现要分割为两个集合,所以我们直接判断左右就好了,num[0]和num[n-1]较大的一个。
- m>=3,这时候我们发现我们就可以不管最大值的位置划分出只有最大值的子序列,所以就是直接输出max。
还是那句话,细心就是王道,我之前就是忘记了m==2这种情况了。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <stack>#include <cmath>#include <cstdio>#include <algorithm>#define N 400010#define LL __int64#define inf 0x3f3f3f3f 0#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1const int mod = 1000000007;using namespace std;int num[N];int main() { cin.sync_with_stdio(false); int n, m; int a, b; while (cin >> n >> m) { a = 0; b = 0; for (int i = 0; i < n; i++) { cin >> num[i]; if (num[a] > num[i]) { a = i; } if (num[b] < num[i]) { b = i; } } if (m == 1) { cout << num[a] << endl; } else if (m == 2) { cout << max(num[0], num[n - 1]) << endl; } else { cout << num[b] << endl; } } return 0;}
阅读全文
0 0
- B. Maximum of Maximums of Minimums --codeforces
- Codeforces 872 B Maximum of Maximums of Minimums
- CodeForces 872B Maximum of Maximums of Minimums
- Codeforces Round #440 div2 B Maximum of Maximums of Minimums
- Codeforces Round #440 B. Maximum of Maximums of Minimums
- Codeforces Round #440 B. Maximum of Maximums of Minimums-【思维】
- Maximum of Maximums of Minimums
- 【Codeforces Round #440 (Div. 2) B】Maximum of Maximums of Minimums
- Codeforces Round #440 (Div. 2)B. Maximum of Maximums of Minimums
- Codeforces Round #440 (Div. 2) B. Maximum of Maximums of Minimums
- #440 Div.2 B. Maximum of Maximums of Minimums 水
- CF 440 div2 B.Maximum of Maximums of Minimums
- codeforce Maximum of Maximums of Minimums(区间划分 求区间最小值最大值问题)
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)B. Maximum of Maximums of
- NOJ [1316] D Minimums of Sum
- Review of codeforces 486B
- CodeForces 150B- Quantity of Strings 推算..
- codeforces B. Restoration of the Permutation
- java 中如何创建不可变并且static的map
- 使input文本框不可编辑的3种方法
- 第10章 快到碗里来——DirectX大局观认知
- Java生成PDF报表
- 一文总结学习 Python 的 14 张思维导图
- Codeforces 872 B Maximum of Maximums of Minimums
- leetcode 581 Shortest Unsorted Continuous Subarray
- Codeforces 872 A Search for Pretty Integers
- 欢迎使用CSDN-markdown编辑器
- 十大基础实用算法及其拓展
- sql中通过from接一个查询结果
- Java 计算两个日期相差的天数
- LeetCode689. Maximum Sum of 3 Non-Overlapping Subarrays
- linux-命令