Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈,贪心)
来源:互联网 发布:desmume mac键盘 编辑:程序博客网 时间:2024/05/19 07:26
题目链接
题意: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;}
0 0
- Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈,贪心)
- Codeforces Round #330 (Div. 2) C. Warrior and Archer(贪心博弈)
- Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈)
- Codeforces Round #330 (Div. 2)C. Warrior and Archer【博弈+逆向思维】
- Codeforces Round #330 (Div. 2)C. Warrior and Archer
- CodeForces 595C Warrior and Archer(贪心博弈)
- codeforces 595C Warrior and Archer(博弈)
- Codeforces Round #330 (Div. 1) A. Warrior and Archer
- [CodeForces 595C] Warrior and Archer (无胜负最优值博弈)
- codeforces 594A Warrior and Archer [对称博弈]【博弈】
- Codeforces Round #228 (Div. 2) E Fox and Card Game(贪心博弈)
- Codeforces 594A - Warrior and Archer (思维)
- Codeforces Round #288 (Div. 2) C. Anya and Ghosts 贪心
- Codeforces Round #346 (Div. 2) C. Tanya and Toys 贪心
- Codeforces Round #419 (Div. 2) C. Karen and Game【贪心】
- Codeforces Round #406 (Div. 2) C 博弈
- Codeforces Round #263 (Div. 2) C. Appleman and Toastman(贪心)
- Codeforces Round #277.5 (Div. 2)---C. Given Length and Sum of Digits (贪心)
- quartz设置时间表达式
- iOS开发UI基础—手写控件,frame,center和bounds属性
- 关于打包Android工程是报错 Proguard returned with error code 1. See console解决办法”
- ”南大软院大神养成计划“_第五天的学习“
- GDI创建BMP图
- Codeforces Round #330 (Div. 2)C. Warrior and Archer(博弈,贪心)
- poj 2240 Arbitrage
- uva 297
- 经典的计算机书单
- CSS定位position属性
- oracle查询约束条件
- 聊聊JVM的年轻代
- 【JAVA笔记——道】Hadoop设计模式--抽象类
- git查看某一次提交修改的文件列表