BZOJ2091: [Poi2010]The Minima Game

2091: [Poi2010]The Minima Game

Time Limit: 10 Sec  Memory Limit: 259 MB
Submit: 243  Solved: 163
[Submit][Status]

Description

给出N个正整数,AB两个人轮流取数,A先取。每次可以取任意多个数,直到N个数都被取走。
每次获得的得分为取的数中的最小值,A和B的策略都是尽可能使得自己的得分减去对手的得分更大。
在这样的情况下,最终A的得分减去B的得分为多少。

Input

第一行一个正整数N (N <= 1,000,000),第二行N个正整数(不超过10^9)。

Output

一个正整数,表示最终A与B的分差。

Sample Input

3
1 3 1

Sample Output

2

HINT

第一次A取走3,第二次B取走两个1,最终分差为2。

Source

鸣谢 JZP

题解:

巧妙的DP!!!

动态规划,一个人一定是从大到小拿牌,dp[i]表示还剩第i小的牌,能够获得的最大收益,显然答案是dp[n]。然后对于一个dp[i]只有两种情况,第一种是只拿第i大的,获得收益是a[i]-dp[i-1],要么不拿第i大的,收益为dp[i-1]取max即可。

还是思维方式的问题啊。。。

好题!赞!

代码:

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<iostream>
 7 #include<vector>
 8 #include<map>
 9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 1000000+5
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
22 #define mod 1000000007
23 using namespace std;
24 inline int read()
25 {
26     int x=0,f=1;char ch=getchar();
27     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
28     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
29     return x*f;
30 }
31 int n,a[maxn],dp[maxn];
32 int main()
33 {
34     freopen("input.txt","r",stdin);
35     freopen("output.txt","w",stdout);
36     n=read();
37     for1(i,n)a[i]=read();
38     sort(a+1,a+n+1);
39     for1(i,n)dp[i]=max(dp[i-1],a[i]-dp[i-1]);
40     printf("%d\n",dp[n]);
41     return 0;
42 }

时间: 2024-08-05 05:15:59

BZOJ2091: [Poi2010]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 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 m

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 t

BZOJ 2091: [Poi2010]The Minima Game

Description 每次可以任取数字,使用最优策略让差最大. Sol DP. 一开始我写了个单调队列贪心,然后狂WA不止... 正着做有后效性,因为前面的决策无法保证在后面是最优秀的,但如果倒这做就没有后效性了..感觉倒着做这种想法总是容易忽略,它对前面的影响应该多考虑一下. 然后DP就可以了...比较简单的DP.. Code /************************************************************** Problem: 2091 User:

[POI2010]GRA-The Minima Game

OJ题号:洛谷3507 如果选了$k_i$,那么你的对手就可以选上所有$\geq{k_i}$的数.那么他其中获得的分数也一定$\geq{k_i}$. 如果你选了$k_i$以及所有$\geq{k_i}$的数,那么对手无论怎么选,所获得的分数都一定$<{k_i}$,无论如何都不会超过你. 因此,若要保证最优,如果选了$k_i$,同时一定要选上所有$\geq{k_i}$的数. 我们可以将这n个数从小到大排序. 设${k_0}\sim{k_i}$中,双方最大差为$f_i$.易得DP方程$f_i=max(

BZOJ 2091 Poi2010 The Minima Game 动态规划

题目大意:给定n个数,两个人轮流取,每次可以取走任意一些数,获得的分值是这些数中的最小值 两个人都想让自己的分值-对方的分值最大,求最终先手得分-后手得分 显然每个人取走的都是当前剩下的数中最大的一些数 那么考虑倒着做,令fi表示剩余最小的i个数时先手-后手的最大差值 那么有DP方程fi=max{aj+1?fj}(0≤j<i) 维护个最大值就行了 #include <cstdio> #include <cstring> #include <iostream> #i

[POI2010] GRA-The Minima Game - 贪心,dp,博弈论

给出N个正整数,AB两个人轮流取数,A先取.每次可以取任意多个数,直到N个数都被取走.每次获得的得分为取的数中的最小值,A和B的策略都是尽可能使得自己的得分减去对手的得分更大.在这样的情况下,最终A的得分减去B的得分为多少. 引理 先手一定从大到小取若干个连续的数 倒过来考虑,设 \(f[i]\) 表示取完了从小到大的前 \(i\) 个数,当前局面下先手减去后手的最大值 显然有 \(f[i] = Max(a[j]-f[j-1])\) 这样暴力转移是 \(O(n^2)\) 的,考虑优化 观察这个转

省选之前的未完成的计划(截至到省选)

PLAN OF THE COMING HEOI good problems:-bzoj4823:[Cqoi2017]老C的方块 [*]-bzoj3171:[Tjoi2013]循环格 [*]-bzoj4200:[Noi2015]小园丁与老司机 [*]-bzoj1061:[Noi2008]志愿者招募 [*]-bzoj3600:没有人的算术 [*]-bzoj2806:[Ctsc2012]Cheat [*]-bzoj2219:数论之神 [*]-bzoj2595:[Wc2008]游览计划 [*]-bzoj

(DP) bzoj 2091

[bzoj2091]The Minima Game 2014年10月20日2040 Description 给出N个正整数,AB两个人轮流取数,A先取.每次可以取任意多个数,直到N个数都被取走.每次获得的得分为取的数中的最小值,A和B的策略都是尽可能使得自己的得分减去对手的得分更大.在这样的情况下,最终A的得分减去B的得分为多少. Input 第一行一个正整数N (N <= 1,000,000),第二行N个正整数(不超过10^9). Output 一个正整数,表示最终A与B的分差. Sample

波兰题目补全计划

Introduce 本人比较喜欢做波兰的题目,感觉这些题目十分清真,思维也比较好.欢迎同样喜欢波兰题目的OIer来交流.以下是我有记录地刷过的题目. 比较好的题吧:BZOJ #3746.[POI2015]Czarnoksi??nicy okr?g?ego sto?u source:XXII OI - Etap I - Zadanie Czarnoksi??nicy okr?g?ego sto?u notes: 动态规划我的题解http://www.cnblogs.com/TSHugh/p/882