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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 200100;
int a[N], n;
/*
二分塔顶的值把大于等于这个值的变为1小于变为0
可以发现如果有多个1或0连在一起那么他们就无法被分开他会一直往上走
也就是说,最后那组先走到顶那组就赢了,那就要看哪组离中心更近
那会不会存在两个不同阵营的组距离一样远能,你会发现这是不可能的:
因为如果距离相等那么中间一定是奇数位置我们用1和0,交替隔开两组那么最后一个位置肯定会和左边或者右边一样又形成一个组所这两个组要么都是1要么都是0
*/
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;
}