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. Py3快速下载地址

    pip3.exe install 包名称 -i  http://mirrors.aliyun.com/pypi/simple  --trusted-host mirrors.aliyun.com

  2. uboot启动后在内存中运行裸机程序hello

    如题,实现过程中发现3额问题,先写下来,待解答: 1.uboot启动后再dnw上打印许多信息,我想改变其中的打印信息或加上自己的打印信息以证明程序运行到何处.修改完后重新编译uboot.bin. 在D ...

  3. Duplicate headers received from server

    This ones a little old but was high in the google ranking so I thought I would throw in the answer I ...

  4. Object -C NSNumber -- 笔记

    // //  main.m //  NSNumber // //  Created by facial on 24/8/15. //  Copyright (c) 2015 facial_huo. A ...

  5. C# 网络编程之网页简单下载实现

    这是根据<C#网络编程实例教程>中学到的知识实现的一个C#网页简单下载器,其中涉及到的知识主要是HTTP协议编程中相关类:HttpWebRequest类.HttpWebResponse类. ...

  6. java相关的路径获取 (转载 http://tomfish88.iteye.com/blog/971255)

    在jsp和class文件中调用的相对路径不同.在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getProp ...

  7. Android 快速开发系列 打造万能的ListView GridView 适配器

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38902805 ,本文出自[张鸿洋的博客] 1.概述 相信做Android开发的写 ...

  8. Linux之make 、makefile的使用方法

    ◊make是什么? make是一个命令工具,是一个解释makefile中指令的命令工具.它可以简化编译过程里面所下达的指令,当执行 make 时,make 会在当前的目录下搜寻 Makefile (o ...

  9. GSON 简介 示例

    Gson简介 目前解析json最常用的三种工具:org.json(Java常用的解析),fastjson(阿里巴巴出的),Gson(Google出的),解析速度最快的是Gson. Gson的全名为Go ...

  10. 日期 bootsrtap-datatimepicker and bootstrap-datepicker 控件支持中文

    引用 bootsrtap-datatimepicker and bootstrap-datepicker 控件,发现官方控件不支持中文 1,bootstrap-datepicker - >解决方 ...