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不止... 正着做有后效性,因为前面的决策无法保证在后面是最优秀的,但如果倒这做 ...
随机推荐
- CodeVS 1789 最大获利
1789 最大获利 2006年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 新的技术正冲击着 ...
- 很好的DP思路,字符串比较次数
题目: https://leetcode.com/problems/distinct-subsequences/?tab=Description 一般没有明显思路的情况下,都要想想DP,用下Divid ...
- google在线測试练习题3
Problem The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. ...
- 10.Intellij IDEA svn的使用详解
转自:https://www.2cto.com/kf/201703/614858.html 首先提一句,IDEA对各种的版本控制工具的支持是非常好的,打开系统设置界面,就可以看到他有专门的一栏 Ver ...
- java9新特性-10-语法改进:UnderScore(下划线)使用的限制
1.使用说明 在java 8 中,标识符可以独立使用“_”来命名: 但是,在java 9 中规定“_”不再可以单独命名标识符了,如果使用,会报错:
- html页面颜色名称和颜色值转换
public static string ToHtmlColor(string colorName) { try { if (colorName.StartsWith("#")) ...
- javascript常用收集一下
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcEl ...
- App开发Native.js入门指南
概述 Native.js技术,简称NJS,是一种将手机操作系统的原生对象转义,映射为JS对象,在JS里编写原生代码的技术.如果说Node.js把js扩展到服务器世界,那么Native.js则把js扩展 ...
- Windows下安装Scrapy方法及常见安装问题总结——Scrapy安装教程
这几天,很多朋友在群里问Scrapy安装的问题,其实问题方面都差不多,今天小编给大家整理一下Scrapy的安装教程,希望日后其他的小伙伴在安装的时候不再六神无主,具体的教程如下. Scrapy是Pyt ...
- centOS7下 安装nodejs+nginx+mongodb+pm2部署vue项目
一.购买服务器并远程连接 1.购买服务器和域名 可以选择阿里云或者是其他的厂商的服务器.然后会获得服务器ip地址,用户名和密码. 购买域名,将域名绑定到ip地址上. 2.下载xshell,winscp ...