题目描述

Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them:
Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types of spells in stock:
Doubles health of the creature (hpi := hpi·2);
Assigns value of health of the creature to its damage (dmgi := hpi).
Spell of first type can be used no more than a times in total, of the second type — no more than b times in total. Spell can be used on a certain creature multiple times. Spells can be used in arbitrary order. It isn't necessary to use all the spells.
Max is really busy preparing for his final exams, so he asks you to determine what is the maximal total damage of all creatures he can achieve if he uses spells in most optimal way.

题目大意

给你两种操作,一个操作是让hp变成原来的两倍,另一个是让dmg值变成hp值,求最大的dmg的值和。

100分解法

其实比较好想,因为每次hp变大,必然会使和对应的dmg值的差距变小或者比dmg大的更多,我们就大胆的假设把\(a\)全用在一个人身上时,这个答案最优。
那么关于\(b\)的操作,就一定是hp比dmg大的多的要用\(b\),这样我们的贪心策略就好了。

100分代码

#include<bits/stdc++.h>
#define LL long long
#define N 200005
using namespace std;
struct node{LL hp,d;}fi[N];
int n,a,b;
LL ans;
LL r(){LL x=0,w=0;char ch=0;while(!isdigit(ch))w|=ch=='-',ch=getchar();while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return w?-x:x;}
bool cmp(node a,node b){return a.hp-a.d>b.hp-b.d;}//按照差值排序
int main(){
    n=r(),a=r(),b=r();
    for(int i=1;i<=n;i++)fi[i]=(node){r(),r()};
    sort(fi+1,fi+1+n,cmp);
    for(int i=1;i<=b;i++)ans+=max(fi[i].d,fi[i].hp);
    for(int i=b+1;i<=n;i++)ans+=fi[i].d; //先算出处理b的答案
    LL sum=ans;
    for(int i=1;i<=b;i++)ans=max(ans,sum-max(fi[i].d,fi[i].hp)+(fi[i].hp<<a));//开始处理a的答案
    sum=sum-max(fi[b].d,fi[b].hp)+fi[b].d;
    for(int i=b+1;i<=n&&b;i++)ans=max(ans,sum-fi[i].d+(fi[i].hp<<a));
    printf("%I64d\n",ans);
    return 0;
}

[CF976E]Well played!的更多相关文章

  1. Educational Codeforces Round 43 E. Well played!(贪心)

    E. Well played! time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. 完美解决iis下JWplayer提示Error loading media: File could not be played错误

    最近开发项目需要使用JWplayer插件播放视频,但是无论换那个版本.换什么样的视频总是提示Error loading media: File could not be played错误,废了好大的劲 ...

  3. Educational Codeforces Round 43 E&976E. Well played! 贪心

    传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...

  4. Codeforces976E Well played! 【贪心】

    题目分析: 由于乘二的收获很大,所以我们可以证明乘的数一定是同一个,接着排序后依次选取,判断一下即可. 题目代码: #include<bits/stdc++.h> using namesp ...

  5. [Codeforces976E]Well played!(贪心)

    [不稳定的传送门] Solution 首先可以证明,hp翻倍的操作一定是在同一个生物上最优 Code #include <cstdio> #include <algorithm> ...

  6. HTML5笔记2——HTML5音/视频标签详解

    音视频的发展史 早期:<embed>+<object>+文件 问题:不是所有浏览器都支持,而且embed不是标准. 现状:Realplay.window media.Quick ...

  7. [转载]Java 8 日期&时间 API

    Java 8 日期和时间 声明 本文转自http://www.journaldev.com/2800/java-8-date-localdate-localdatetime-instant,以mark ...

  8. html5 audio总结

    前言 html5中对音频,视频播放原生支持.最近做了一个音乐播放器,得益于快过年了,才能抽出一点时间来总结一下.总的来说,html5对audio的支持非常强大, 难怪flash要死.浏览器上装播放插件 ...

  9. 05. Web大前端时代之:HTML5+CSS3入门系列~H5 多媒体系

    Web大前端时代之:HTML5+CSS3入门系列:http://www.cnblogs.com/dunitian/p/5121725.html 1.引入 概述 音频文件或视频文件都可以看做是一个容器文 ...

随机推荐

  1. MySQL设计SQL语句优化规范

    原文:http://bbs.landingbj.com/t-0-240751-1.html 1. 使用mysql explain 对sql执行效率进行检测 ,explain显示了mysql如何使用索引 ...

  2. vue处理异步数据踩过的坑

    在开发时,由于数据是异步的导致页面在render 时data是空值 出现报错和警告. 我是这么处理的 把data先写出一个空的完整结构.暂时是这么处理 或者用三元表达式进行赋值监听.data ?myd ...

  3. js去除数组重复成员

    js去除数组重复成员 第一种思路是:遍历要删除的数组arr, 把元素分别放入另一个数组tmp中,在判断该元素在arr中不存在才允许放入tmp中 用到两个函数:for ...in 和 indexOf() ...

  4. C#复习笔记(3)--C#2:解决C#1的问题(可空值类型)

    可空值类型 C#2推出可空类型来表示可以为null的值类型.这是一个呼声很高的需求,因为在常用的数据库中都是允许某些值类型可为空的.那么为什么值类型就不能为空呢?内存中用一个全0的值来表示null,但 ...

  5. Oracle undo 表空间不可用

    由于某次不小心操作,在切换表空间时没有成功,由于把undo的配置参数 undo_management值设置为MANUAL所以在启动数据库时没有报任何错误,但是给表插入数据时报错了,回滚段不可用的错误. ...

  6. mysql_linux(centos7 mysql 5.7.19)

    centos7  mysql 5.7.19安装 1.解压文件 [root@centos3 ~]# tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.g ...

  7. bnu——GCD SUM (莫比乌斯反演)

    题目:GCD SUM 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=39872 算法:莫比乌斯反演.优化 #include<stdio.h& ...

  8. JavaMail入门第一篇 邮件简介及API概述

    现如今,电子邮件在我们的生活当中扮演着越来越重要的角色,我们每个人几乎都会与其打交道(至少时不时我们都会接收到莫名其妙的垃圾邮件),在工作中,使用邮件进行交流沟通,可以使我们的工作有迹可循,也显的较为 ...

  9. Laravel技巧:使用load、with预加载 区别

    1.使用load $posts = Post::all(); $posts->load('user'); 2.使用with $posts = Post::with('user')->all ...

  10. Unit 1.前端基础之html

    一.什么是html 定义:全称是超文本标记语言(HyperText Markup Language),它是一种用于创建网页的标记语言.标记语言是一种将文本(Text)以及文本相关的其他信息结合起来,展 ...