AT2672 Coins
传送门
按理说想到转化问题之后就不难了吧,可是我还是不会写
一个很容易想到的转化就是差分,将银币数和铜币数都减去金币数,这样就转化为\(x+y+z\)个钱币选\(y\)个银币和\(z\)个铜币的最大数量了
然后我这个菜逼就不会做了
设总钱币数为\(n\),银币\(x[i]\)个,铜币\(y[i]\)个,就可以按\(x[i]-y[i]\)排序
然后很显然的就是一定是前\(k\)个选银币,后\(n-k\)个选铜币(显而易见的贪心)
枚举\(k\),用一个堆来维护就好了
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std;
void read(int &x){
char ch;bool ok;
for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=1e5+10;
int x,y,z,n;long long ans,sum[maxn],num;
struct oo{int x,y;}a[maxn];
bool cmp(oo a,oo b){return a.x-a.y<b.x-b.y;}
priority_queue<int,vector<int>,greater<int> >q;
int main(){
read(x),read(y),read(z),n=x+y+z;
for(rg int i=1,u,v,w;i<=n;i++){
read(u),read(v),read(w);
num+=u,v-=u,w-=u;
a[i].x=v,a[i].y=w;
}
sort(a+1,a+n+1,cmp);long long now=0;
for(rg int i=1;i<=z;i++)now+=a[i].y,q.push(a[i].y);
for(rg int i=z+1;i<=n;i++){
sum[i-1]=now,q.push(a[i].y);
now+=a[i].y,now-=q.top();q.pop();
}
sum[n]=now;
while(!q.empty())q.pop();now=0;
for(rg int i=n;i>=n-y+1;i--)now+=a[i].x,q.push(a[i].x);
for(rg int i=n-y;i>=z;i--){
ans=max(ans,now+sum[i]+num),q.push(a[i].x);
now+=a[i].x,now-=q.top();q.pop();
}
printf("%lld\n",ans);
}
AT2672 Coins的更多相关文章
- [LeetCode] Arranging Coins 排列硬币
You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...
- ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力
Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS Memory Limit:65536KB 64bit IO Fo ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- csuoj 1119: Collecting Coins
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec Memo ...
- Coins
Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hi ...
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)
http://poj.org/problem?id=3260 Description Farmer John has gone to town to buy some farm supplies. ...
- POJ3260The Fewest Coins[背包]
The Fewest Coins Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6299 Accepted: 1922 ...
- POJ1742 Coins[多重背包可行性]
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 34814 Accepted: 11828 Descripti ...
随机推荐
- freeMarker(八)——程序开发指南之配置(Configuration)
学习笔记,选自freeMarker中文文档,译自 Email: ddekany at users.sourceforge.net 1.基本内容 配置(configuration)就是 freemark ...
- 基于v4l2 ffmpeg x264的视频远程监控(附上编译好的库文件)
说明:主要是基于ghostyu网友整理的< arm mini2440 基于v4l2 ffmpeg x264的视频远程监控>.自己做了一遍,遇到不少问题,就整理记录下来. 1.平台 硬件:a ...
- DEBUG命令说明
Debug在学习汇编的过程中,担任着一个非常重要的角色,是一个极其重要的调试工具,所以学会它是必须得. 命令格式 功能说明 A [地址] 输入汇编指令 C [范围] 起始地址 对由“范围”指定的区域与 ...
- Shiro 权限管理filterChainDefinitions过滤器配置
博客转载:http://blog.csdn.net/userrefister/article/details/47807075 /** * Shiro-1.2.2内置的FilterChain * @s ...
- Amaze UI 框架
Amaze UI 框架:官方网址 http://amazeui.org/ 演示地址 http://t.amazeui.org/kitchen-sink/#/ 该UI框架提供了 桌面系统WEB框架 和 ...
- js右击事件
先贴代码: <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF ...
- py xrange
range(5)是列表 xrang(5)是生成器 每次调用 xrange(5),返回相应的值,比起range(5) 直接返回一个列表,性能好.
- 多对多 hibernate映射
数据库: create table EMPLOYEE ( EMPID NUMBER(6) not null, EMPNAME VARCHAR2(32) ) alter table EMPLOYEE a ...
- JavaScript的内部对象
JavaScript的内部对象 按创建方式不同分为:使用变量声明的隐性对象,使用new创建的显性对象 隐性对象 在赋值和声明后就是一个隐性对象,隐性对象不支持prototype属性,也无法随意扩展对象 ...
- Ubuntu 解决:当执行`sudo apt-get update`命令时 出现的 “apt-get 404 Not Found Package Repository Errors” 问题
Ubuntu 解决:当执行sudo apt-get update或者sudo apt-get install命令是出现的 "apt-get 404 Not Found Package Rep ...