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
3
1 3 1
1 3 1
Sample Output
2
HINT
第一次A取走3,第二次B取走两个1,最终分差为2。
Source
#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[n];
return 0;
}