您的位置:首页 > 其它

Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈,贪心)

2015-11-20 17:43 417 查看
题目链接

题意:n个数,俩人轮流删除数,使得最后剩下2个,一个希望俩数之间的距离最小,一个希望剩下的距离最大

解答:证明见官方题解,假设最后剩下[L,R ]的区间,那么一定是一个人删了[L,R]之间的数,另一个删除了[L,R]之外的数字。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define X first
#define Y second
#define cl(a,b) memset(a,b,sizeof(a))
typedef pair<int,int> P;
const int maxn=300005;
const LL inf=1<<27;
const LL mod=1e9+7;

LL a[maxn];

int main(){
int n;scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lld",&a[i]);
}
sort(a,a+n);
LL ans=1LL<<62;
for(int i=0;i<n;i++)if(i+n/2<n){
ans=min(ans,a[i+n/2]-a[i]);
}
printf("%lld\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: