题目描述

Alice and Bob learned the minima game, which they like very much, recently.

The rules of the game are as follows.

A certain number of cards lies on a table, each inscribed with a positive integer.

The players make alternate moves, Alice making the first one.

A move consists in picking an arbitrary positive number of cards from the table.

For such move the player receives a number of points equal to the minimum of the numbers inscribed on the cards he collected.

The game ends when the last card is removed from the table.

The goal of each player is maximizing the difference between their and their opponent's score.

Alice and Bob have duly noted that there is an optimal strategy in the game.

Thus they are asking you to write a program that, for a given set of cards, determines the outcome of the game when both players play optimally.

给出N个正整数,AB两个人轮流取数,A先取。每次可以取任意多个数,直到N个数都被取走。每次获得的得分为取的数中的最小值,A和B的策略都是尽可能使得自己的得分减去对手的得分更大。在这样的情况下,最终A的得分减去B的得分为多少。

输入输出格式

输入格式:

In the first line of the standard input there is one integer  () given, denoting the number of cards.

The second line holds  positive integers  (), separated by single spaces, that are inscribed on the cards.

输出格式:

Your program should print out a single line with a single integer to the standard output - the number of points by which Alice wins over Bob, assuming they both play optimally; if it is Bob who has more points, the result should be negative.

输入输出样例

输入样例#1:

3
1 3 1
输出样例#1:

2

如果选了i,那么>=i的数都要选。

否则对方一定会更优。

证明:

假如选完>=i的数的状态为s1,没选完的为s2。

对方可以先选完>=i的数,那么他接下来面对的状态就是s1了。

所有在s2下,一切s1有的决策他都能选择。

同时他还多了一些决策。

所有s2下他一定比s1优。

所以我们先将n个数从小到大排序。

f[i]表示剩下了1..i这个前缀的max(先手-后手)。

枚举先手决策,f[i]=max(a[j]-f[j-1]),j=1..i

边界是f[0]=0。

a[j]-f[j-1]的前缀max是很好维护的。

 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=;
inline void read(int &n)
{
char c=getchar();n=;bool flag=;
while(c<''||c>'') c=='-'?flag=,c=getchar():c=getchar();
while(c>=''&&c<='') n=n*+c-,c=getchar();flag==?n=-n:n=n;
}
int a[MAXN];
int n;
int main()
{
int n;read(n);
int MAX=-,MIN=0x7fff;
for(int i=;i<=n;i++) read(a[i]);
sort(a+,a+n+);
int ans=;
for(int i=;i<=n;i++)
if(ans<a[i]-ans)
ans=a[i]-ans;
printf("%d",ans);
return ;
}

最新文章

  1. String basePath = request.getScheme()+&quot;://&quot;+request.getServerName()+&quot;:&quot;+request.getServerPort()+pat----------&lt;base&gt;元素有关
  2. Swift编程语言资料合集
  3. Dynamics AX 2012 R2 安装 AIF IIS上的Web服务
  4. InfluxDB Cli中查询结果中time格式显示设置
  5. BZOJ 2763: [JLOI2011]飞行路线 spfa dp
  6. c#操作XML文件的通用方法
  7. codeforces 632F. Magic Matrix
  8. undefined 与void 0
  9. Python机器学习介绍(Python Machine Learning 中文版)
  10. 【Qt编程】3D迷宫游戏
  11. 【转】Android-Input input&amp;按键布局文件
  12. 20-matlab全排列-函数调用
  13. OPENQUERY (Transact-SQL)
  14. windows 安装lua-5.3.4 --引用自https://blog.csdn.net/wangtong01/article/details/78296369
  15. opencv版本的问题
  16. 深入探讨 Java 类加载器(转)
  17. Ubuntu18.04安装和配置 Java JDK 和 JRE,并卸载自带OpenJDK
  18. golang ---image
  19. jvm 性能调优 经验总结---转
  20. Java中的HashMap的工作原理是什么?

热门文章

  1. Linux学习总结(12)——Linux必须学会的60个命令
  2. 基于LevelDB的高可用ActiveMQ集群
  3. Unity 相机花式分屏
  4. 我在SharePoint行业的从业经历(一)
  5. 【RQNOJ】460 诺诺的队列
  6. Getting Started with MongoDB (C# Edition)
  7. poj--1703--Find them, Catch them(并查集巧用)
  8. Minikube之Win10单机部署Kubernetes(k8s)自动化容器操作的开源平台
  9. BZOJ 3110 线段树套线段树
  10. POJ 3204 网络流的必须边