BZOJ2590 [Usaco2012 Feb]Cow Coupons
好吧。。。想了半天想错了。。。虽然知道是贪心。。。
我们每次找没有被买的两种价格最小的牛,比较a = 当前差价最大的 + 当前优惠券价格最小的牛与b = 当前非优惠券价格最小的牛
所以。。。我们要
先维护两个小根堆,分别表示用优惠券买的牛的价格和不用优惠券买的牛的价格
还有个叫Recover的大根堆,表示当前几个用优惠券的那几头牛的差价(差价定义为非优惠价格与优惠价格的差值)
a与b哪个小就买哪个。。。
/**************************************************************
Problem: 2590
User: rausen
Language: C++
Result: Accepted
Time:140 ms
Memory:3332 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <queue> using namespace std;
typedef long long ll;
const int N = ;
struct data{
int w, v;
data(void){}
data(int x, int y) : w(x), v(y) {}
};
inline bool operator < (const data a, const data b){
return a.v > b.v;
}
int cnt, n, k;
int p[N], c[N];
bool vis[N];
ll m;
priority_queue <data> h, H;
priority_queue <ll, vector<ll>, greater<ll> > Re; inline int read(){
int x = ;
char ch = getchar();
while (ch < '' || ch > '')
ch = getchar();
while (ch >= '' && ch <= ''){
x = x * + ch - '';
ch = getchar();
}
return x;
} int main(){
int i;
ll cost;
data T;
n = read(), k = read();
scanf("%lld", &m);
for (i = ; i <= n; ++i){
p[i] = read(), c[i] = read();
h.push(data(i, c[i]));
H.push(data(i, p[i]));
}
while (!Re.empty()) Re.pop();
for (i = ; i <= k; ++i)
Re.push();
while (m > && cnt < n){
while (vis[h.top().w])
h.pop();
while (vis[H.top().w])
H.pop();
if (Re.top() + h.top().v < H.top().v){
T = h.top(), cost = Re.top() + T.v;
if (m < cost) break;
m -= cost;
Re.pop();
Re.push(p[T.w] - c[T.w]);
vis[T.w] = ;
}else{
T = H.top(), cost = T.v;
if (m < cost) break;
m -= cost;
vis[T.w] = ;
}
++cnt;
}
printf("%d\n", cnt);
return ;
}
BZOJ2590 [Usaco2012 Feb]Cow Coupons的更多相关文章
- 【贪心】【堆】bzoj2590 [Usaco2012 Feb]Cow Coupons
每个物品有属性a,b 考虑在仅仅用光优惠券时的最优方案. 显然是按照b排序,取前K个. 但是我们还要尽可能去取剩余的. 假设朴素地取剩余的话,应该把剩余的对a排序,然后尽量去取. 但是有可能对其用优惠 ...
- 2590: [Usaco2012 Feb]Cow Coupons
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 306 Solved: 154[Su ...
- [Usaco2012 Feb] Cow Coupons
[Usaco2012 Feb] Cow Coupons 一个比较正确的贪心写法(跑得贼慢...) 首先我们二分答案,设当前答案为mid 将序列按照用券之后能省掉的多少排序,那么我们对于两种情况 \(m ...
- USACO 2012 Feb Cow Coupons
2590: [Usaco2012 Feb]Cow Coupons Time Limit: 10 Sec Memory Limit: 128 MB Submit: 349 Solved: 181 [Su ...
- [Usaco 2012 Feb]Cow coupons牛券:反悔型贪心
Description Farmer John needs new cows! There are N cows for sale (1 <= N <= 50,000), ...
- 洛谷P3045 [USACO12FEB]牛券Cow Coupons
P3045 [USACO12FEB]牛券Cow Coupons 71通过 248提交 题目提供者洛谷OnlineJudge 标签USACO2012云端 难度提高+/省选- 时空限制1s / 128MB ...
- BZOJ1631: [Usaco2007 Feb]Cow Party
1631: [Usaco2007 Feb]Cow Party Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 459 Solved: 338[Submit ...
- BZOJ3301: [USACO2011 Feb] Cow Line
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 67 Solved: 39[Submit ...
- BZOJ1697: [Usaco2007 Feb]Cow Sorting牛排序
1697: [Usaco2007 Feb]Cow Sorting牛排序 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 387 Solved: 215[S ...
随机推荐
- 20145307陈俊达《网络对抗》Exp9 Web安全基础实践
20145307陈俊达<网络对抗>Exp9 Web安全基础实践 基础问题回答 1.SQL注入攻击原理,如何防御? SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求 ...
- max3232
max3232采用专有低压差发送器输出级,利用双电荷泵在3.0V至5.5V电源供电时能够实现真正的RS-232性能,器件仅需四个0.1uF的外部小尺寸电荷泵电容.max3232确保在120kbps数据 ...
- Github使用教程详解
官方网站:http://git-scm.com Git是目前世界上最先进的分布式版本控制系统(没有之一). Git有什么特点?简单来说就是:高端大气上档次! 一.Git安装 在Linux上安装Git ...
- linux内核启动参数解析及添加
1.环境: ubuntu16.04 Linux jello 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_64 x ...
- Winform中使用折叠窗口
使用此处的控件 http://www.codeproject.com/Articles/18401/XPanderControls 注意事项 使用之前需要先添加winform自带的toolStripC ...
- 3D CNN for Video Processing
3D CNN for Video Processing Updated on 2018-08-06 19:53:57 本文主要是总结下当前流行的处理 Video 信息的深度神经网络的处理方法. 参考文 ...
- 如何插入sql数据
原:http://blog.csdn.net/Weicleer/article/details/47608289
- python 正则表达式匹配特定浮点数
def is_decimal(num): import re #以数字开头,小数点后保留1位数字或两位数字或者没有小数部分 dnumre = re.compile(r""" ...
- c++ 容器元素填充(generate)
#include <iostream> // cout #include <algorithm> // generate #include <vector> // ...
- 测试报告 之 testNG + Velocity 编写自定义html测试报告
之前用testNG自带的test-outputemailable-report.html,做出的UI自动化测试报告,页面不太好看. 在网上找到一个新的报告编写,自己尝试了一下,埋了一些坑,修改了输出时 ...