2091: [Poi2010]The Minima Game
2017-01-01 09:24
435 查看
2091: [Poi2010]The Minima Game
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 504 Solved: 348
[Submit][Status][Discuss]
Description
给出N个正整数,AB两个人轮流取数,A先取。每次可以取任意多个数,直到N个数都被取走。每次获得的得分为取的数中的最小值,A和B的策略都是尽可能使得自己的得分减去对手的得分更大。
在这样的情况下,最终A的得分减去B的得分为多少。
Input
第一行一个正整数N (N <= 1,000,000),第二行N个正整数(不超过10^9)。Output
一个正整数,表示最终A与B的分差。Sample Input
31 3 1
Sample Output
2HINT
第一次A取走3,第二次B取走两个1,最终分差为2。Source
鸣谢 JZP[Submit][Status][Discuss]
不妨先将所有数字从小到大排好序。
贪心地想,每次取数字,都是从最大的那个数开始倒着往前连续取几个
如果中间有间隔,对方只要选了中间缺漏的数字,对方的结果不会更劣
定义f[i]:前i个数字,先手最大分差
那么,f[i] = max(A[j+1] - f[j]),优化显然
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<vector> #include<queue> #include<set> #include<map> #include<stack> #include<bitset> #include<ext/pb_ds/priority_queue.hpp> using namespace std; const int maxn = 1E6 + 10; int n,cur = 1,f[maxn],A[maxn]; int getint() { char ch = getchar(); int ret = 0; while (ch < '0' || '9' <ch) ch = getchar(); while ('0' <= ch && ch <= '9') ret = ret*10 + ch - '0',ch = getchar(); return ret; } int main() { #ifdef DMC freopen("DMC.txt","r",stdin); #endif n = getint(); int Max = 0; for (int i = 1; i <= n; i++) A[i] = getint(); sort(A + 1,A + n + 1); for (int i = 0; i <= n; i++) { f[i] = Max; Max = max(Max,A[i+1] - f[i]); } cout << f ; return 0; }
相关文章推荐
- 【POI2010】【BZOJ2091】The Minima Game
- BZOJ 2091 Poi2010 The Minima Game 动态规划
- bzoj 2091: [Poi2010]The Minima Game 动态规划
- 【bzoj2091】【Poi2010】【The Minima Game】【dp】
- BZOJ 2091 [Poi2010]The Minima Game
- 【bzoj2091】[Poi2010]The Minima Game
- BZOJ2091: [Poi2010]The Minima Game
- BZOJ2091: [Poi2010]The Minima Game
- BZOJ2091[Poi2010] The Minima Game
- bzoj2091[Poi2010]The Minima Game DP
- [bzoj2091] [Poi2010]The Minima Game
- 【bzoj2091】[Poi2010]The Minima Game dp
- bzoj2091[Poi2010]The Minima Game DP
- bzoj 2091: [Poi2010]The Minima Game【博弈论+贪心+dp】
- bzoj2091【Poi2010】The Minima Game
- 【bzoj2091】 [Poi2010]The Minima Game
- [POI2010]GRA-The Minima Game
- [POI2010]GRA-The Minima Game
- BZOJ2091 [Poi2010]The Minima Game
- BZOJ2091: [Poi2010]The Minima Game