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.
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 ;
}