题解:CF2003B Turtle and Piggy Are Playing a Game 2
第一个人会优先删除一个最小值,第二个人会优先删除一个最大值,那么剩下的就是就只中间值了。所以答案是原序列的第 \(\lfloor \frac{x}{2} \rfloor + 1\) 小的数。
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int arr[N],n;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
cin>>n;
for(int i=1;i<=n;i++)
cin>>arr[i];
sort(arr+1,arr+n+1);
int idx=(1+n)/2;
if(!(n&1))
idx+=1;
cout<<arr[idx]<<endl;
}
return 0;
}

浙公网安备 33010602011771号