题目描述

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])。

代码:

#include<cstdio>
#include<algorithm>
#define maxn 1000007
using namespace std;
int n,f[maxn],a[maxn];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",&a[i]);
sort(a+1,a+1+n);
for(int i=1;i<=n;++i)
f[i]=max(f[i-1],a[i]-f[i-1]);
printf("%d\n",f[n]);
return 0;
}

洛谷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. 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)

    洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...

  3. [洛谷P3501] [POI2010]ANT-Antisymmetry

    洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...

  4. 洛谷 P3496 [POI2010]GIL-Guilds

    P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...

  5. 洛谷 P3505 [POI2010]TEL-Teleportation

    P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...

  6. 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解

        这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...

  7. [洛谷P3509][POI2010]ZAB-Frog

    题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上).问对于从每个点开始跳,跳$m$次, ...

  8. [洛谷P3512 [POI2010]PIL-Pilots]

    题目链接: 传送门走这里 题目分析: 感觉不是很难啊--不像是蓝题(AC量也不像)恶意评分? 少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还 ...

  9. 洛谷P1274-魔术数字游戏

    Problem 洛谷P1274-魔术数字游戏 Accept: 118    Submit: 243Time Limit: 1000 mSec    Memory Limit : 128MB Probl ...

随机推荐

  1. suse 源的添加与删除,以及源地址

    地址 一个是上海交大的,http://ftp.sjtu.edu.cn/opensuse/update/ 葡萄牙的: http://ftp.nux.ipb.pt/pub/dists/opensuse/u ...

  2. 冷扑大师AI简史:你用德扑来游戏,人家用来发Science

    前言 人类又输了...... 创新工场组织的一场“人工智能和顶尖牌手巅峰表演赛中”,机器人AI冷扑大师赢了人类代表队龙之队 792327 记分牌,最后 200 万奖励归机器人所有. 在围棋项目上人类的 ...

  3. 类型:Oracle;问题:oracle 查询表详细信息;结果:oracle查询表信息(索引,外键,列等)

    oracle查询表信息(索引,外键,列等) oracle中查询表的信息,包括表名,字段名,字段类型,主键,外键唯一性约束信息,索引信息查询SQL如下,希望对大家有所帮助: 1.查询出所有的用户表sel ...

  4. 问题:oracle if;结果:Oracle IF语句的使用

    oracle 之if..else用法 oracle条件分支用法 a.if...then b.if...then... else c.if...then... elsif.... else 实例 1 问 ...

  5. MongoDB中的查询

    MongoDB中文文档:http://docs.mongoing.com/manual-zh/contents.html 这里以集合名称为test为例,数据库通过for循环插入一些测试数据,键分别为: ...

  6. Python之条件语句以及循环

    Python代码的缩进规则.具有相同缩进的代码被视为代码块 缩进请严格按照Python的习惯写法:4个空格,不要使用Tab,更不要混合Tab和空格,否则很容易造成因为缩进引起的语法错误. 注意: if ...

  7. Pandoc+markdown生成slides

    Pandoc+markdown生成slides 参考:http://blog.csdn.net/pizi0475/article/details/50955900 1.安装 http://pandoc ...

  8. Android指针管理:RefBase,SP,WP

    Android中通过引用计数来实现智能指针,并且实现有强指针与弱指针.由对象本身来提供引用计数器,但是对象不会去维护引用计数器的值,而是由智能指针来管理. 要达到所有对象都可用引用计数器实现智能指针管 ...

  9. springmvc 处理器方法返回的是modelandview 重定向到页面

  10. 【总结整理】WMS、WMTS、WFS

    参考:http://www.cnblogs.com/naaoveGIS/p/5508882.html WMTS:WMTS是OGC制定的一种发布瓦块地图的Web服务规范,wms主要是动态地图,wmts是 ...