题目描述

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 ;
}

P3507 [POI2010]GRA-The Minima Game的更多相关文章

  1. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  2. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  3. bzoj2091【Poi2010】The Minima Game

    直接dp就好了 每个人肯定会去选最大的,用dp[i]表示选了后i个点时先手-后手的最大值(因为从后往前扫才好转移啊 QwQ~) dp[i]=max(c[j]-dp[j-1]),(j<=i) 直接 ...

  4. luoguP3507 [POI2010]GRA 性质 + 动态规划

    题目大意: 给定\(n\)个正整数,\(a, b\)两个人轮流取,\(a\)先手 每次可以取任意多的数,直到取完,每次的得分为取的数中的最小值 \(a, b\)都会使自己的得分减去对手的得分更大,询问 ...

  5. BZOJ2091: [Poi2010]The Minima Game

    2091: [Poi2010]The Minima Game Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 243  Solved: 163[Subm ...

  6. bzoj2091: [Poi2010]The Minima Game DP

    2091: [Poi2010]The Minima Game DP 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2091 思路 这类问题好迷 ...

  7. 2091: [Poi2010]The Minima Game

    2091: [Poi2010]The Minima Game 链接 分析: 首先排序后,一定是选的连续的一段. f[i]表示前i个位置,先手-后手的最大得分. 那么考虑第i个位置是否选,如果选,先手选 ...

  8. [bzoj2091][Poi2010]The Minima Game_动态规划

    The Minima Game bzoj-2091 Poi-2010 题目大意:给出N个正整数,AB两个人轮流取数,A先取.每次可以取任意多个数,直到N个数都被取走.每次获得的得分为取的数中的最小值, ...

  9. BZOJ 2091: [Poi2010]The Minima Game

    Description 每次可以任取数字,使用最优策略让差最大. Sol DP. 一开始我写了个单调队列贪心,然后狂WA不止... 正着做有后效性,因为前面的决策无法保证在后面是最优秀的,但如果倒这做 ...

随机推荐

  1. 第一个JavaWeb工程

    这个工程主要用来研究log4j,所以就只有一个页面,希望以后慢慢进步. java动态生成网页主要使用servlet.把请求拦截下来,处理后返回结果. 这里创建的是一个maven工程. 结构如下:

  2. 基于Masonry自己主动计算cell的高度

    /** * This is a very very helpful category for NSTimer. * * @author huangyibiao * @email huangyibiao ...

  3. BZOJ 2683 简单题 cdq分治+树状数组

    题意:链接 **方法:**cdq分治+树状数组 解析: 首先对于这道题,看了范围之后.二维的数据结构是显然不能过的.于是我们可能会考虑把一维排序之后还有一位上数据结构什么的,然而cdq分治却可以非常好 ...

  4. 一、奇妙插件Tampermonkey的简单安装教程

    奇妙插件Tampermonkey的简单安装教程 1.下载 对于浏览器而言,一般的功能并不能满足"特殊用户的需求".这时候就须要插件来帮忙了.那么讲到插件的支持多又常见的浏览器必定要 ...

  5. Configuration file schema for the .NET Framework

    https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/index Runtime Settings ...

  6. 如何解读「量子计算应对大数据挑战:中国科大首次实现量子机器学习算法」?——是KNN算法吗?

    作者:知乎用户链接:https://www.zhihu.com/question/29187952/answer/48519630 我居然今天才看到这个问题,天……本专业,有幸听过他们这个实验的组会来 ...

  7. The while statement

    Computers are often used to automate repetitive tasks. Repeating identical or similar tasks without ...

  8. python 3.x 学习笔记5 (装饰器)

    1.装饰器: 本质是函数,(装饰其他函数)就是为其他函数添加附加功能 原则: 1)不能修改被装饰的函数的源代码 2)不能修改被装饰的函数的调用方式 2.实现装饰器知识储备: 1)函数即“变量” 2)高 ...

  9. Android项目实战(五十六):获取WebView加载的url的请求错误码

    例如需求,我有一个WebView 加载一个url, 该url对应的网页本身自带下拉刷新 ,但是网页本身会有出现400 500 等异常请求错误码 这时候网页加载失败,页面本身的下拉是无法使用的,要求重新 ...

  10. SqlServer 删除日志

    1  数据库在使用过程中会使日志文件不断增加,使得数据库的性能下降,并且占用大量的磁盘空间.SQL Server数据库都有log文件,log文件记录用户对数据库修改的操作.可以通过直接删除log文件和 ...