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. Object -C NSValue -- 笔记

    // //  main.m //  NSValue // //  Created by facial on 26/8/15. //  Copyright (c) 2015 facial_huo. Al ...

  2. 要缩小通过两个触摸点的观点(iOS)

    于AppDelegate.m档,创建一个视图控制器 #import "MAYAppDelegate.h" #import "MAYViewController.h&quo ...

  3. angularjs手动解析表达式($parse)

    <!DOCTYPE html> <html lang="zh-CN" ng-app="app"> <head> <me ...

  4. php 时间转换

    在数据库读出的数据,都是字符类型的,所以需要转换: 时间的转换:用date ()函数来实现时间格式; date() 函数默认时间是1970/01/01/ 00:00:00; 要想得到想要的时间就还得用 ...

  5. Hibernate 关联查询 相关错误

    错误提示: could not resolve property: 确定有相关属性时,记得使用 criteria.createAlias @ManyToOne 若可能为null 要加上 @NotFou ...

  6. (转)关于c#中的事件

    原文链接http://blog.csdn.net/joyhen/article/details/8500211 如有不明白的地方欢迎加QQ群14670545 探讨 最近在看委托,然后看到事件,以前一直 ...

  7. Windows计划任务 未能启动

    近期在windows server 2003上运行的备份脚本,在7月23日之后,没再运行,在计划任务里看到的状态是:未能启动.结果手动运行了一下备份脚本,没有问题,可以正常运行,但是在计划任务里为什么 ...

  8. 数据库(批处理, 事务,CachedRawSetImpl类

    链接对象son产生的Statement SQL对象对数据库提交的任何一条语句都会被立刻执行 不方便我们进行一些连招操作 我们可以关闭它的自动提交,然后操作完再开,这过程称作事务 con.setAuto ...

  9. C/C++中unsigned char和char的区别

    代码: #include <cstdio> #include <iostream> using namespace std; int main(){ unsigned char ...

  10. JS浏览器关闭时清空cookie

    function addCookie(objName,objValue,objHours){    var str = objName + "=" + escape(objValu ...