[CodeForces 595C] Warrior and Archer (无胜负最优值博弈)
来源:互联网 发布:忘记mac的开机密码 编辑:程序博客网 时间:2024/05/21 22:34
CodeForces - 595C
一根数轴上分布着偶数个点,A和 B每次轮流从上面拿走一个点
A希望最后剩下来的两个点距离尽量近,B则希望尽量远
若两个人都采用最佳策略,则最后剩下的两个点的距离是多少
这很显然是一个博弈,属于无胜负求最优值的游戏
既然是博弈,我们就要寻找这个游戏的最佳策略是什么
对坐标排序后,假设最后剩下的两个点下标为
首先, A希望最后两个点尽量近,那么他会尽可能地去拿两边的点
也就是说,他不可能去拿
而 B则相反,他不可能去拿
这样
所以最后,
由于 A先行动,那么结果一定对 A最有利,即对于A的最优解
答案就是所有满足
小小总结一下博弈:
1) 先手占有主动权,通常可以控制局面,如果条件允许,一定对其最优
2) 先手得利,则后手必然吃亏,后手得利,先手则必然吃亏,二者不相容
#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <set>#include <queue>using namespace std;typedef pair<int,int> Pii;typedef long long LL;typedef unsigned long long ULL;typedef double DBL;typedef long double LDBL;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define Pow2(a) (a*a)const int maxn=2e5+10;int N;int inpt[maxn];int main(){ scanf("%d", &N); int ans=1e9; for(int i=1; i<=N; i++) scanf("%d", &inpt[i]); sort(inpt+1,inpt+1+N); for(int i=N/2+1; i<=N; i++) ans=min(ans, inpt[i]-inpt[i-N/2]); printf("%d\n", ans); return 0;}
0 0
- [CodeForces 595C] Warrior and Archer (无胜负最优值博弈)
- codeforces 595C Warrior and Archer(博弈)
- CodeForces 595C 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 594A Warrior and Archer [对称博弈]【博弈】
- Codeforces Round #330 (Div. 2)C. Warrior and Archer【博弈+逆向思维】
- Codeforces Round #330 (Div. 2)C. Warrior and Archer
- Codeforces 594A - Warrior and Archer (思维)
- Codeforces Round #330 (Div. 1) A. Warrior and Archer
- CodeForces 347C Alice and Bob(博弈)
- codeforces 347 c Alice and Bob(博弈 && 数学)
- CodeForces 312B--Archer
- CodeForces 312B Archer
- codeforces-312B Archer
- Codeforces 388C Fox and Card Game 博弈
- codeforces 167C Wizards and Numbers(找规律,博弈)
- 易语言学习第二十五课----制作一个小工具
- 使用qrcode自动生成二维码
- spring mybatis 整合后mapper接口注入失败问题
- boost库windows&linux下编译
- UIBezierPath精讲
- [CodeForces 595C] Warrior and Archer (无胜负最优值博弈)
- Ubuntu server intall Ubuntu Oracle 12c Release 1
- 排序sort与qsort的区别
- 关于Yii2中微信支付或支付宝支付异步通知无效
- 函数式编程
- SVN的安装部署
- JDK源码分析Java.lang.Boolean的浅析——单例模式的应用(使我们更省内存)
- Object-c------第一个OC程序
- 成为Java顶尖程序员 ,看这10本书就够了