题目描述

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. 常用Oracle分析函数详解

    学习步骤:1. 拥有Oracle EBS demo 环境 或者 PROD 环境2. copy以下代码进 PL/SQL3. 配合解释分析结果4. 如果网页有点乱请复制到TXT中查看 /*假设一个经理代表 ...

  2. 【Python环境】matplotlib - 2D 与 3D 图的绘制

    2015-10-30数据科学自媒体 类MATLAB API 最简单的入门是从类 MATLAB API 开始,它被设计成兼容 MATLAB 绘图函数. 让我们加载它: from pylab import ...

  3. sql语句中的问号是干什么的???

    1.实例代码一: String sql = "SELECT userid,name FROM tuser WHERE userid=? AND password=?" ;  pst ...

  4. ORACLE体系结构一 (物理结构)- 数据文件、日志文件、控制文件和参数文件

    一.物理结构Oracle物理结构包含了数据文件.日志文件.控制文件和参数文件 1.数据文件每一个ORACLE数据库有一个或多个物理的数据文件(data file).一个数据库的数据文件包含全部数据库数 ...

  5. Java界面设计

    ---------------siwuxie095                             Java SE(Java Standard Edition) 即 Java 标准版, 一般也 ...

  6. ThinkPHP的URL模式

    ThinkPHP的URL模式有四种,默认是PATHINFO模式,其他三种分别为:普通模式.REWRITE和兼容模式. 一.PATHINFO模式 浏览器输入格式为: http://localhost/d ...

  7. Struts2框架04 struts和spring整合

    目录 1 servlet 和 filter 的异同 2 内存中的字符编码 3 gbk和utf-8的特点 4 struts和spring的整合 5 struts和spring的整合步骤 6 spring ...

  8. Eigen介绍及简单使用

    博客转载自:https://blog.csdn.net/fengbingchun/article/details/47378515 Eigen是可以用来进行线性代数.矩阵.向量操作等运算的C++库,它 ...

  9. 算法Sedgewick第四版-第1章基础-2.3 Quicksort-001快速排序

    一. 1.特点 (1)The quicksort algorithm’s desirable features are that it is in-place (uses only a small a ...

  10. java中byte是什么类型,和int有什么区别

    byte字节型,int是整型,byte是8bit,int是32bit. byte可以转换为int,但int转byte可能会报错,因为精度问题,可能会超过上界.char也可转int,互转int的关系和b ...