You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
2.1 KiB

2 years ago
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 200100;
int a[N], n;
/*
10
10
:
10,10
*/
bool check(int x) {
//从中间向两边开始查找连续的0或1
for (int i = 0; i <= n - 1; i++) {
//左侧存在连续0,或者右侧存在连续0,那么最终结果肯定为0这与我们事先约定的塔顶元素是x,大于等于x 的都是1出现矛盾说明我们给的x不对数字1太少了x给大了需要减小x
if ((a[n - i] < x && a[n - i - 1] < x) || (a[n + i] < x && a[n + i + 1] < x)) return false;
//左侧存在连续1或者右侧存在连续1那么最终结果肯定为1符合我们事先的约定,数字1数量够用可以再把x调大一点
if ((a[n - i] >= x && a[n - i - 1] >= x) || (a[n + i] >= x && a[n + i + 1] >= x)) return true;
}
//如果一路检查都没有找到连续的0和1 ,说明是特例情况:
// 0101 0 1010
// 1010 1 0101
// 这样的东东,最左(右)下角的值>=塔顶值
return a[1] >= x;
}
int main() {
//加快读入
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 1; i <= 2 * n - 1; i++) cin >> a[i]; //全排列
int l = 1, r = 2 * n - 1;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid))
l = mid + 1;
else
r = mid - 1;
}
printf("%d\n", l - 1);
return 0;
}