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

题解:
巧妙的DP!!!
动态规划,一个人一定是从大到小拿牌,dp[i]表示还剩第i小的牌,能够获得的最大收益,显然答案是dp[n]。然后对于一个dp[i]只有两种情况,第一种是只拿第i大的,获得收益是a[i]-dp[i-1],要么不拿第i大的,收益为dp[i-1]取max即可。
还是思维方式的问题啊。。。
好题!赞!
代码:
 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1000000+5
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,a[maxn],dp[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)a[i]=read();
sort(a+,a+n+);
for1(i,n)dp[i]=max(dp[i-],a[i]-dp[i-]);
printf("%d\n",dp[n]);
return ;
}

BZOJ2091: [Poi2010]The Minima Game的更多相关文章

  1. [bzoj2091][Poi2010]The Minima Game_动态规划

    The Minima Game bzoj-2091 Poi-2010 题目大意:给出N个正整数,AB两个人轮流取数,A先取.每次可以取任意多个数,直到N个数都被取走.每次获得的得分为取的数中的最小值, ...

  2. bzoj2091: [Poi2010]The Minima Game DP

    2091: [Poi2010]The Minima Game DP 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2091 思路 这类问题好迷 ...

  3. 2091: [Poi2010]The Minima Game

    2091: [Poi2010]The Minima Game 链接 分析: 首先排序后,一定是选的连续的一段. f[i]表示前i个位置,先手-后手的最大得分. 那么考虑第i个位置是否选,如果选,先手选 ...

  4. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  5. 【bzoj2091】[Poi2010]The Minima Game dp

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

  6. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  7. P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  8. BZOJ 2091: [Poi2010]The Minima Game

    Description 每次可以任取数字,使用最优策略让差最大. Sol DP. 一开始我写了个单调队列贪心,然后狂WA不止... 正着做有后效性,因为前面的决策无法保证在后面是最优秀的,但如果倒这做 ...

  9. [POI2010]GRA-The Minima Game

    OJ题号:洛谷3507 思路: 如果选了$k_i$,那么你的对手就可以选上所有$\geq{k_i}$的数.那么他其中获得的分数也一定$\geq{k_i}$. 如果你选了$k_i$以及所有$\geq{k ...

随机推荐

  1. css 改变scroll样式

    /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/ ::-webkit-scrollbar { width: 16px; height: 16px; background-color: #F5 ...

  2. ffmpeg错误隐藏框架分析

    本文主要是分析ffmpeg的错误隐藏框架,故解码流程此处不会特地进行讨论,网上其他地方其实也有不少介绍相关流程的了,但发现基本没有介绍错误隐藏流程的,故本文希望能填补这个空白. 我们直接从decode ...

  3. [Javascript] What is JavaScript Function Currying?

    Currying is a core concept of functional programming and a useful tool for any developer's toolbelt. ...

  4. vc++上的MFC的对象序列化和反序列化

      注意点: 1. 必须类型序列化声明    DECLARE_SERIAL( Person )  2. 必须写出实现宏 IMPLEMENT_SERIAL(Person, CObject, VERSIO ...

  5. Asp.Net mvc筛选器中返回信息中断操作

    在mvc中,使用response.end()或Response.Redirect("url"); 是无法阻止请求继续往下执行的.如果在action中,可以我们可以使用return ...

  6. phpmyadmin登陆提示#2002 无法登录 MySQL 服务器和设置自增

    看看mysql启动没有,结果是mysql服务没有启动,找了半天,是这个原因,那就右键计算机->管理->服务->启动mysql服务 设置自增:在显示出来的一行字段定义中把浏览器的滚动条 ...

  7. Ubuntu11.10打开XDMCP,使用XManager远程管理

    ubuntu11.10-desktop-i386.iso缺省安装使用lightdm作为缺省登录器,这里说说开启XDMCP进行远程登录 首先关闭防火墙 sudo ufw disables Ubuntu所 ...

  8. 高放的c++学习笔记之模板与泛型编程

    函数模板 作用 有很多时候参数的类型以及返回值的类型是可变的,我们通过定义模板来让函数能更灵活的运用. 我们设计一个比较函数,如果能比较的两个参数是int型的,两个参数也可能都是string型的,单独 ...

  9. Yandex 2013Q(Atoms: There and Back Again-贪心+模拟+List)

    Atoms: There and Back Again Time limit 2 seconds Memory limit 256Mb Input stdin Output stdout Legend ...

  10. 在thread 引用pthread_t 空指针的问题

    错误 pthread_t *thr; pthread_create(thr,NULL,threadhander(),NULL); 正确 pthread_t thr; pthread_create(&a ...