Codeforces976E Well played! 【贪心】
题目分析:
由于乘二的收获很大,所以我们可以证明乘的数一定是同一个,接着排序后依次选取,判断一下即可。
题目代码:
#include<bits/stdc++.h>
using namespace std; const int maxn = ; int n,a,b; struct node{
int hp,dm;
}d[maxn]; int cmp(node alpha,node beta){
return alpha.hp-alpha.dm > beta.hp-beta.dm;
} void read(){
scanf("%d%d%d",&n,&a,&b);
for(int i=;i<=n;i++) scanf("%d%d",&d[i].hp,&d[i].dm);
sort(d+,d+n+,cmp);
} void work(){
int hh = ;
long long ext = ,ans = ;
for(int i=;i<=a;i++) hh *= ;
int pt;
for(pt=;pt<=min(b,n);pt++){
if(d[pt].hp-d[pt].dm <= ) break;
ans += d[pt].hp;
}
for(int i=pt;i<=n;i++) ans += d[i].dm;
long long em = ans;ext = ans;pt--;
if(b == ){printf("%lld",ext);return;}
for(int i=;i<=n;i++){
em = ans;
if(i<=pt){
em = em-d[i].hp+(1ll*d[i].hp*hh);
ext = max(ext,em);
}else{
if(pt < b){
em = em+(1ll*d[i].hp*hh)-d[i].dm;
ext = max(ext,em);
}else{
em = em-d[pt].hp+(1ll*d[i].hp*hh)-d[i].dm+d[pt].dm;
ext = max(ext,em);
}
}
}
printf("%lld",ext);
} int main(){
read();
work();
return ;
}
Codeforces976E Well played! 【贪心】的更多相关文章
- [Codeforces976E]Well played!(贪心)
[不稳定的传送门] Solution 首先可以证明,hp翻倍的操作一定是在同一个生物上最优 Code #include <cstdio> #include <algorithm> ...
- Educational Codeforces Round 43 E&976E. Well played! 贪心
传送门:http://codeforces.com/contest/976/problem/E 参考:https://www.cnblogs.com/void-f/p/8978658.html 题意: ...
- 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 ...
- Codeforces Round #401 (Div. 2) A B C 水 贪心 dp
A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...
- hdoj--1087--Super Jumping! Jumping! Jumping!(贪心)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1383 Solved: 582[Submit][St ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]
1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 786 Solved: 391[Submit][S ...
随机推荐
- 如何屏蔽SkylineGlobe提供的三维地图控件上的快捷键
SkyllineGlobe提供的 <OBJECT ID=" TerraExplorer3DWindow" CLASSID="CLSID:3a4f9192-65a8- ...
- php中按值传递和按引用传递的一个问题
php中传递变量默认是按照值传递. 简单举个例子: <?php function testArray($arr){// &$arr $arr = array(1,2,3,); } $ar ...
- 苹果与Windows双系统时间不同步的解决办法
步骤:打开C盘>Windows>System32,找到cmd.exe,右键以管理员的身份运行. Reg add HKLM\SYSTEM\CurrentControlSet\Control\ ...
- Ionic app 通知在Moto 360 Watch上显示通知(1)
手机与Moto 360 watch配对之后,watch上会接收到微信消息的通知,那么我们就可以利用这个特性开发一个App,在Watch显示我们自己的通知,具体过程如下 1.手机扫描二维码安装ticwa ...
- Verilog对数据进行四舍五入(round)与饱和(saturation)截位
转自https://www.cnblogs.com/liujinggang/p/10549095.html 一.软件平台与硬件平台 软件平台: 操作系统:Windows 8.1 64-bit 开发套件 ...
- PHP实现验证码制作
captcha.php(PHP产生验证码并储存Session): <?php //开启Session session_start(); //绘制底图 $image = imagecreatetr ...
- UWP简单示例(三):快速开发2D游戏引擎
准备 IDE:Visual Studio 图形 API:Win2D MSDN 教程:UWP游戏开发 游戏开发涉及哪些技术? 游戏开发是一门复杂的艺术,编码方面你需要考虑图形.输入和网络 以及相对独立的 ...
- Jmeter(三十五)_精确实现网页爬虫
Jmeter实现了一个网站文章的爬虫,可以把所有文章分类保存到本地文件中,并以文章标题命名 它原理就是对网页提交一个请求,然后把返回的所有值提取出来,利用ForEach控制器去实现遍历.下面来介绍一下 ...
- Centos7部署elasticsearch并且安装ik分词以及插件kibana
第一步 下载对应的安装包 elasticsearch下载地址:https://www.elastic.co/cn/downloads/elasticsearch ik分词下载:https://gith ...
- underscore.js常用的API
过滤 var bigClassData = _.filter(data.Results, function (num) { return num.ClassType == 0; }); var fin ...