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不止... 正着做有后效性,因为前面的决策无法保证在后面是最优秀的,但如果倒这做 ...
随机推荐
- 红黑树(RBTREE)之上-------构造红黑树
该怎么说呢,现在写代码的速度还是很快的,很高兴,o(^▽^)o. 光棍节到了,早上没忍住,手贱了一般,看到*D的优惠,买了个机械键盘,晚上就到了,敲着还是很舒服的,和老婆炫耀了一把哈哈. 光棍节再去* ...
- Centos6.6 系统优化
1:最小化安装 2:修改网卡 vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0HWADDR=52:54:00:0e:c2:c3TYPE ...
- 面向对象设计(OOD)七大原则
这篇文章我会不停的维护它,它将会越来越长,但它是关于我在面向对象中的一些学习的思考心得.希望对自己对各位都能实用处. 开篇前,说明一下写这篇文章的原因.原因是由于设计模式.由于设计模式里的各种 ...
- 【通信框架】Google的开源通信框架protobuf概述
在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com QQ:1494713801 一.作用 protobuf(Protocol Buffers)是Google内部 ...
- struts2 validate验证
转自:https://blog.csdn.net/houpengfei111/article/details/9038233 自定义拦截器 要自定义拦截器需要实现com.opensymphony.xw ...
- 11.字符,字符常见开发,_itoa函数
各种字符所占字节 wchar_t wch = L'我'; //占4个字节 char ch;//占1个字节 printf("%d\n", sizeof("A")) ...
- POJ 2110 二分+暴搜
题意: 给你一个矩阵 ,你能往各个方向走(不走出去就行),每次只能上下左右走一格,问路径上的点权最大值和最小值的差最小是多少. 思路: 首先 二分最后的答案, 暴力枚举当前的区间是啥. DFS 就OK ...
- js封装each函数
function each(ele,callback){ if(Object.prototype.toString.call(ele) == "[object Array]"){ ...
- tomcat web容器工作原理
Tomcat的模块结构设计的相当好,而且其Web 容器的性能相当出色.JBoss直接就使用了Tomcat的web容器,WebLogic的早期版本也是使用了Tomcat的代码.Web容器的工作过程在下面 ...
- LINUX 上源代码安装与配置samba服务,支持从windows上读写LINUX文件。
###动机###在windows编写代码文件比较方便,因为有source insight.但是需要在LINUX上编译.一种办法就是使用samba文件共享. [1] 下载samba代码.按照config ...