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 ...
随机推荐
- JAVA堆内存和栈内存初步了解
一.堆内存和栈内存 程序运行时内存分配有三种:静态存储分配,栈式存储分配,堆式存储分配 1.静态存储分配: 在程序编译时就可以确定数据目标在运行时所需要的内存,因此在编译时就为其分配固定大小的内存. ...
- C语言访问MCU寄存器的两种方式
转自http://blog.csdn.net/liming0931/article/details/7752248 单片机的特殊功能寄存器SFR,是SRAM地址已经确定的SRAM单元,在C语言环境下对 ...
- React 版 V2EX 社区( react & react-router & axios & antd ui)
目录 项目简介 在线演示 截图演示 踩坑 项目简介(1/4) Github: https://github.com/bergwhite/v2ex-react 项目使用React.Reac-router ...
- Django-进阶 分页,中间件
知识预览 分页 中间件 回到顶部 分页 Django的分页器(paginator) view from django.shortcuts import render,HttpResponse # Cr ...
- flask+uswgi+nginx+python3.6的venv发布网站ubuntu14.04
---------------------------nginx--------------- sudo apt-get install nginx sudo apt-get remove nginx ...
- B+树索引和哈希索引的明显区别是:
如果是等值查询,那么哈希索引明显有绝对优势,因为只需要经过一次算法即可找到相应的键值:当然了,这个前提是,键值都是唯一的.如果键值不是唯一的,就需要先找到该键所在位置,然后再根据链表往后扫描,直到找到 ...
- varnish安装和配置
实验环境:CentOS7 Varnish是高性能开源的反向代理服务器和HTTP缓存服务器. #varnish服务器:172.16.252.142 [root@varnish localhost]#yu ...
- mysql软文
常用的MySQL复杂查询语句写法 http://www.blogjava.net/bolo/archive/2015/02/02/422649.html mysql sql常用语句大全 http: ...
- windows、Linux 测试服务器、电脑的某些个端口是否打开
测试远程端口是否开放包括两种方法: 一. 命令行的形式 二.代码 先参考我的博客 windows.Linux 开放端口 一.命令行的形式 两个命令:telnet.nc(netcat) 两种网络层协议: ...
- 项目一:第一天 1、项目概述 2、环境搭建(重点) 3、Jquery Easyui 前端UI框架 4、Jquery Ztree 树形插件使用
1.项目环境 注:添加jar包直接在common_parent里面添加. 搭建数据库 create tablespace bos317space datafile 'c:\ bos317.dbf' ...