2091: [Poi2010]The Minima Game

50 篇文章 0 订阅

2091: [Poi2010]The Minima Game

Time Limit: 10 Sec   Memory Limit: 259 MB
Submit: 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

Sample Output

2

HINT

第一次A取走3,第二次B取走两个1,最终分差为2。

Source

[ 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[n];
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值