前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >P3507 [POI2010]GRA-The Minima Game

P3507 [POI2010]GRA-The Minima Game

作者头像
attack
发布2018-04-13 10:23:16
6390
发布2018-04-13 10:23:16
举报

题目描述

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 n(1<=n<=1000000) given, denoting the number of cards. The second line holds n positive integers k1,k2,...,kn(1<=ki<=10^9) 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:

代码语言:javascript
复制
3
1 3 1

输出样例#1:

代码语言:javascript
复制
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是很好维护的。

代码语言:javascript
复制
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<algorithm>
 5 using namespace std;
 6 const int MAXN=12700000;
 7 inline void read(int &n)
 8 {
 9     char c=getchar();n=0;bool flag=0;
10     while(c<'0'||c>'9')    c=='-'?flag=1,c=getchar():c=getchar();
11     while(c>='0'&&c<='9')    n=n*10+c-48,c=getchar();flag==1?n=-n:n=n;
12 }
13 int a[MAXN];
14 int n;
15 int main()
16 {
17     int n;read(n);
18     int MAX=-1,MIN=0x7fff;
19     for(int i=1;i<=n;i++)    read(a[i]);
20     sort(a+1,a+n+1);
21     int ans=0;
22     for(int i=1;i<=n;i++)
23         if(ans<a[i]-ans)    
24             ans=a[i]-ans;
25     printf("%d",ans);
26     return 0;
27 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-09-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目描述
  • 输入输出格式
  • 输入输出样例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档