BZOJ2802 [Poi2012]Warehouse Store 【贪心】
题目链接
题解
这样的问题通常逆序贪心
每个\(A[i]\)只能用来满足后面的\(B[i]\)
就用当前\(A[i]\)不断提供给最小的\(B[i]\)即可
用一个堆维护
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 250005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
struct node{int v,id;};
inline bool operator < (const node& a,const node& b){
return a.v > b.v;
}
priority_queue<node> q;
LL A[maxn],B[maxn];
int n,ans[maxn],ansi;
int main(){
n = read();
REP(i,n) A[i] = read();
REP(i,n) B[i] = read();
node u;
for (int i = n; i; i--){
q.push((node){B[i],i});
while (A[i] && !q.empty()){
u = q.top(); q.pop();
if (A[i] >= u.v) ans[++ansi] = u.id,A[i] -= u.v;
else u.v -= A[i],q.push(u),A[i] = 0;
}
}
sort(ans + 1,ans + 1 + ansi);
printf("%d\n",ansi);
REP(i,ansi) printf("%d ",ans[i]);
return 0;
}
BZOJ2802 [Poi2012]Warehouse Store 【贪心】的更多相关文章
- bzoj2802 [Poi2012]Warehouse Store 贪心+堆
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2802 题解 我一开始想到了一个比较麻烦的做法. 把每一天按照 \(b_i\) 从小到大排序,\ ...
- BZOJ2802: [Poi2012]Warehouse Store
2802: [Poi2012]Warehouse Store Time Limit: 10 Sec Memory Limit: 64 MBSec Special JudgeSubmit: 121 ...
- [bzoj2802][Poi2012]Warehouse Store_贪心_堆
Warehouse Store bzoj-2802 Poi-2012 题目大意:一家商店的连续n天内,每一天会进货$a_i$个,有且只有一个客人回来买$b_i$个,问至多满足多少人. 注释:$1\le ...
- 【bzoj2802】[Poi2012]Warehouse Store 贪心+堆
题目描述 有一家专卖一种商品的店,考虑连续的n天.第i天上午会进货Ai件商品,中午的时候会有顾客需要购买Bi件商品,可以选择满足顾客的要求,或是无视掉他.如果要满足顾客的需求,就必须要有足够的库存.问 ...
- BZOJ2802——[Poi2012]Warehouse Store
1.题目巨短,自己看看吧 2.分析:这道题,想了半天dp还是想不到,最后看题解发现是个贪心的思想,我们维护一个堆,如果这个人不能加入就把他和堆上最大的进行比较,然后搞搞就行了 #include < ...
- 【BZOJ 2802】 2802: [Poi2012]Warehouse Store (贪心)
2802: [Poi2012]Warehouse Store Description 有一家专卖一种商品的店,考虑连续的n天.第i天上午会进货Ai件商品,中午的时候会有顾客需要购买Bi件商品,可以选择 ...
- bzoj 2802 [Poi2012]Warehouse Store STL
[Poi2012]Warehouse Store Time Limit: 10 Sec Memory Limit: 64 MBSec Special JudgeSubmit: 621 Solve ...
- 【BZOJ】2802: [Poi2012]Warehouse Store(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=2802 自己yy了一下... 每一次如果够那么就买. 如果不够,考虑之前买过的,如果之前买过的比当前花 ...
- BZOJ_2802_[Poi2012]Warehouse Store_堆+贪心
BZOJ_2802_[Poi2012]Warehouse Store_堆+贪心 Description 有一家专卖一种商品的店,考虑连续的n天. 第i天上午会进货Ai件商品,中午的时候会有顾客需要购买 ...
随机推荐
- 百度地图在移动端下click无效的解决方案
这是由于百度地图在移动端屏蔽了click事件,在网上找到一种方法,利用touchClick方法来模拟click事件,代码如下(需要JQ插件): //给jquery添加touchClick方法 (fun ...
- Analysis 图标分析 - loadrunner
analysis常见 /
- Go的CSP并发模型
golang的goroutine机制: 一.go 内部有三个对象: P对象(processor) 代表上下文(或者可以认为是cpu),M(work thread)代表工作线程,G对象(g ...
- Hands on Machine Learning with Sklearn and TensorFlow学习笔记——机器学习概览
一.什么是机器学习? 计算机程序利用经验E(训练数据)学习任务T(要做什么,即目标),性能是P(性能指标),如果针对任务T的性能P随着经验E不断增长,成为机器学习.[这是汤姆米切尔在1997年定义] ...
- NO.5:自学python之路------标准库,正则表达式
引言 时间过的好快呀,终于6级也考完了,学习Python的进度也得赶赶了.好的开始这一周的内容. 正文 模块 模块的本质就是‘.py’结尾的文件,它可以用来从逻辑上组织Python代码,它可以是变量. ...
- mongodb基本使用(一)
1.启动.停止和重启mongodb服务 brew services start mongodb ---启动 brew services stop mongodb --停止 brew services ...
- linux命令系列 stat & touch
1. stat - display file or file system status stat命令主要用于显示文件或文件系统的状态,详细信息 事实上,stat命令显示的是文件的I节点信息.Linu ...
- MathExam第二次作业
第二次作业:MathExam 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 20 30 • ...
- 20172324《Java程序设计》第3周学习总结
20172324<Java程序设计>第3周学习总结 教材学习内容总结 随机数,记住要返回的是指定的字符前一个. String类型的一些用法,例如concat(连接),toUpperCase ...
- 任务看板-Monday
工作照