Educational Codeforces Round 43 E&976E. Well played! 贪心
传送门:http://codeforces.com/contest/976/problem/E
参考:https://www.cnblogs.com/void-f/p/8978658.html
题意:
对于每一个生物,有一个ph值和伤害值。现在有a次使ph值乘2的机会,有b次是伤害值等于ph值得机会。
问最后能得到最大的伤害总和是多少。
思路:自己一开始也想的是贪心,但是贪的姿势不正确。明确,a次一定是给同一个生物放大的。但是至于是对哪一个生物放大,还是要用暴力一个一个去找,而不要对排序后第一个值操作;
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iterator>
#include <cmath>
using namespace std; #define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back #define Pll pair<ll,ll>
#define Pii pair<int,int> #define fi first
#define se second #define OKC ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef unsigned long long ull; /*-----------------show time----------------*/
const int maxn = 2e5+;
int a,b,n;
struct node {
ll h,d;
ll w;
}t[maxn];
const ll inf = 0x3f3f3f3f3f3f3f3f;
int main(){
OKC;
cin>>n>>a>>b;
for(int i=; i<=n; i++)
{
cin>>t[i].h>>t[i].d;
t[i].w = t[i].h - t[i].d;
if(t[i].w<)t[i].w = ;
}
ll sum = ;
sort(t+,t++n,[](node a,node b){return a.w>b.w;});
for(int i=; i<=n; i++)
{
if(i<=b)sum += max (t[i].h,t[i].d);
else sum += t[i].d;
}
ll ans = sum;
if(b==)cout<<ans<<endl;
else
{
for(int i=; i<=n; i++)
{
ll tmp = sum;
if(i<=b)
{
tmp -= max(t[i].h,t[i].d);
tmp += 1ll*(t[i].h<<a);
}
else
{
tmp -= t[i].d;
tmp += 1ll*(t[i].h<<a);
tmp += t[b].d;
tmp -= max(t[b].d,t[b].h);
}
if(ans<tmp)ans = tmp;
}
cout<<ans<<endl;
} return ;
}
CF976E
Educational Codeforces Round 43 E&976E. Well played! 贪心的更多相关文章
- Educational Codeforces Round 43
Educational Codeforces Round 43 A. Minimum Binary Number 显然可以把所有\(1\)合并成一个 注意没有\(1\)的情况 view code / ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- 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 ...
- Educational Codeforces Round 43 (Rated for Div. 2) ABCDE
A. Minimum Binary Number time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 7 E. Ants in Leaves 贪心
E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connec ...
- C. Brutality Educational Codeforces Round 59 (Rated for Div. 2) 贪心+思维
C. Brutality time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- C. Playlist Educational Codeforces Round 62 (Rated for Div. 2) 贪心+优先队列
C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
随机推荐
- JAVA从零学习 第一天 邮箱ych1102@163.com QQ382993199
学习编程 听说读写 寻寻渐进 要准备好长期蒙蒙的状态 延迟3个月后明白 机器语言 二级制 1010 1100 0011 汇编语言 助记词表达程序 机器如果执行就需要编译 汇编语言移植性 ...
- Java 获取操作系统相关的内容
package com.hikvision.discsetup.util; import java.lang.reflect.Field; import java.net.InetAddress; i ...
- WPF:window设置单一开启
方法一: Window window = new Window();window.ShowDialog; 方法二: 设置一个判断窗口打开状态的全局控制变量 private bool i ...
- Echarts图表插件(4.x版本)使用(二、带分类筛选的多个图表/实例化多个ECharts,以关系图/force为例)
导读 如果想在一个页面里实例化带分类筛选的多个Echarts该怎么做呢? 曾探讨了带分类选择的关系图显示为自定义图片的需求实现,传送门ECharts图表插件(4.x版本)使用(一.关系图force节点 ...
- Go中的日志及第三方日志包logrus
有别的语言使用基础的同学工作中都会接触到日志的使用,Go中自然也有log相关的实现.Go log模块主要提供了3类接口,分别是 "Print .Panic .Fatal ",对每一 ...
- 如何使用dmidecode命令查看硬件信息
引言 当我们需要获取机器硬件信息时,可使用linux系统自带的dmidecode工具进行查询. dmidecode命令通过读取系统DMI表,显示服务器硬件和BIOS信息.除了可使用dmidecode查 ...
- vue中的虚拟DOM树
什么是虚拟DOM树?(Virtual DOM) 虚拟DOM树其实就是一个普通的js对象,它是用来描述一段HTML片段的 01 当页面渲染的时候Vue会创建一颗虚拟DOM树 02 ...
- 精通Android4.0开发视频【张泽华】-完整版下载
观看须知: 本视频教程为黑马程序员 张泽华老师历经2年时间整理 适合有JavaWeb基础同学学习,教程采用的AVI方式发布,所以看起来很流畅. 视频概括: 1. 本套视频不同于市面上任何一套andro ...
- 优雅的在WinForm/WPF/控制台 中使用特性封装WebApi
优雅的在WinForm/WPF/控制台 中使用特性封装WebApi 说明 在C/S端作为Server,建立HTTP请求,方便快捷. 1.使用到的类库 Newtonsoft.dll 2.封装 HttpL ...
- Sqlserver 使用.net查询被事务锁住处理
在有些应用场景中.事务开了后或能需要再去调用某个DAL读取表中的数据.但DAL里又是新开的链接,由于外面有事务所以这里读的时候就读不到.这种情况下可以在这个DAL的查询里开一个新的事务级别设为允许脏读 ...