P3507 [POI2010]GRA-The Minima Game
题目描述
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.
输入输出样例
3
1 3 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的更多相关文章
- 洛谷 P3507 [POI2010]GRA-The Minima Game
P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...
- 洛谷P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...
- bzoj2091【Poi2010】The Minima Game
直接dp就好了 每个人肯定会去选最大的,用dp[i]表示选了后i个点时先手-后手的最大值(因为从后往前扫才好转移啊 QwQ~) dp[i]=max(c[j]-dp[j-1]),(j<=i) 直接 ...
- luoguP3507 [POI2010]GRA 性质 + 动态规划
题目大意: 给定\(n\)个正整数,\(a, b\)两个人轮流取,\(a\)先手 每次可以取任意多的数,直到取完,每次的得分为取的数中的最小值 \(a, b\)都会使自己的得分减去对手的得分更大,询问 ...
- BZOJ2091: [Poi2010]The Minima Game
2091: [Poi2010]The Minima Game Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 243 Solved: 163[Subm ...
- bzoj2091: [Poi2010]The Minima Game DP
2091: [Poi2010]The Minima Game DP 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2091 思路 这类问题好迷 ...
- 2091: [Poi2010]The Minima Game
2091: [Poi2010]The Minima Game 链接 分析: 首先排序后,一定是选的连续的一段. f[i]表示前i个位置,先手-后手的最大得分. 那么考虑第i个位置是否选,如果选,先手选 ...
- [bzoj2091][Poi2010]The Minima Game_动态规划
The Minima Game bzoj-2091 Poi-2010 题目大意:给出N个正整数,AB两个人轮流取数,A先取.每次可以取任意多个数,直到N个数都被取走.每次获得的得分为取的数中的最小值, ...
- BZOJ 2091: [Poi2010]The Minima Game
Description 每次可以任取数字,使用最优策略让差最大. Sol DP. 一开始我写了个单调队列贪心,然后狂WA不止... 正着做有后效性,因为前面的决策无法保证在后面是最优秀的,但如果倒这做 ...
随机推荐
- jQuery第一课 加载页面弹出一个对话框
<script type="text/javascript"> $(document).ready(function(){ alert("欢迎收看:" ...
- 《Craking the Coding interview》python实现---01
###题目:给定一个字符串,判断其中是否有重复字母###思路:将重复的字符放入到list中,并进行计数统计###实现:伪代码.函数.类实现###伪代码:string=s #给定的字符串list=[] ...
- Java常用知识(长期更新)
1.0转义符 \n:换行 ,\n的作用和print后面的ln相同,可酌情使用 \t:一个制表位(一系列空格) 例: public class Schedule{ public static void ...
- Getting started with Kentico
https://docs.kentico.com/k10tutorial 主面板按照功能分成两行排版 https://docs.kentico.com/k10tutorial/getting-star ...
- [JSOI2008] [BZOJ1567] Blue Mary的战役地图 解题报告 (hash)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1567 Description Blue Mary最近迷上了玩Starcraft(星际争霸 ...
- 3.Linux系统信息
arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS / DMI ...
- CUDA笔记(六)
dim3是NVIDIA的CUDA编程中一种自定义的整型向量类型,基于用于指定维度的uint3 忽然发现需要再搞多机MPI的配置,多机GPU集群.好麻烦.. 这两天考完两门了,还剩下三门,并行计算太多了 ...
- realm怎样支持hashmap
realm不支持hashmap这种形式stackoverflow给出了解决方案http://stackoverflow.com/ques... class MyData extends RealmOb ...
- 数据库Tsql语句创建--约束--插入数据
1.创建数据库 use master go if exists(select * from sysdatabases where name='数据库名字') drop database 数据库名字 g ...
- Linux下安装使用MySQL
网上找那些安装教程比较多的版本,版本只要不是太旧就行. 下载mysql 5.6.28 通用版64位二进制版,二进制版相当于windows的安装包,可以直接安装,如果是源码版,还需要编译后再进行安装. ...