BZOJ2802——[Poi2012]Warehouse Store
1、题目巨短,自己看看吧
2、分析:这道题,想了半天dp还是想不到,最后看题解发现是个贪心的思想,我们维护一个堆,如果这个人不能加入就把他和堆上最大的进行比较,然后搞搞就行了
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 250010
#define LL long long
inline int read(){
char ch = getchar(); int x = 0, f = 1;
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while('0' <= ch && ch <= '9'){
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
struct Node{
int d, u;
inline bool operator < (const Node& rhs) const{
return d < rhs.d;
}
};
priority_queue<Node> Q;
int A[M], B[M];
int tot, a[M];
int main(){
int n = read();
for(int i = 1; i <= n; i ++) A[i] = read();
for(int i = 1; i <= n; i ++) B[i] = read();
LL ans = 0;
for(int i = 1; i <= n; i ++){
ans += A[i];
if(ans >= B[i]) ans -= B[i], Q.push((Node){B[i], i});
else if(!Q.empty() && Q.top().d > B[i]){
ans += Q.top().d; Q.pop();
ans -= B[i], Q.push((Node){B[i], i});
}
}
while(!Q.empty()){
// printf("%d\n", Q.top().d);
a[++ tot] = Q.top().u; Q.pop();
}
sort(a + 1, a + tot + 1);
printf("%d\n", tot);
for(int i = 1; i < tot; i ++) printf("%d ", a[i]);
if(tot) printf("%d\n", a[tot]);
return 0;
}
BZOJ2802——[Poi2012]Warehouse Store的更多相关文章
- BZOJ2802: [Poi2012]Warehouse Store
2802: [Poi2012]Warehouse Store Time Limit: 10 Sec Memory Limit: 64 MBSec Special JudgeSubmit: 121 ...
- BZOJ2802 [Poi2012]Warehouse Store 【贪心】
题目链接 BZOJ2802 题解 这样的问题通常逆序贪心 每个\(A[i]\)只能用来满足后面的\(B[i]\) 就用当前\(A[i]\)不断提供给最小的\(B[i]\)即可 用一个堆维护 #incl ...
- bzoj2802 [Poi2012]Warehouse Store 贪心+堆
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2802 题解 我一开始想到了一个比较麻烦的做法. 把每一天按照 \(b_i\) 从小到大排序,\ ...
- 【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 ...
- [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件商品,可以选择满足顾客的要求,或是无视掉他.如果要满足顾客的需求,就必须要有足够的库存.问 ...
- 【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件商品,中午的时候会有顾客需要购买 ...
随机推荐
- Jquery学习笔记 --ajax删除用户,使用了js原生ajax
主要复习了php的pdo数据库操作,和js的ajax,真麻烦,希望jquery的ajax简单点. index.php: 1 <!DOCTYPE html> 2 <html lang= ...
- CSS系列——前端进阶之路:初涉Less
前言:最近帮一个朋友解决点问题,在查看组件源码的时候涉及到了less语法,这可难倒博主了.没办法,既然用到就要学呗,谁让咱是无所不能的程序猿呢!所以今天来学习下Less,算是笔记,也希望给初学less ...
- 腾讯 auth_token
auth_token 从cookies里取出supertoken=2881515311; function auth_token(str) { var hash = 0; for (var i = 0 ...
- python学习之路 第三天
1.set集合:去掉重复字段 set.difference()找出不同并创建一个新的集合,不改变原来集合: set.difference_update() 改变原来集合,剔除掉括号内容: set.di ...
- canvas-图片翻转
图片90度翻转 在canvas中插入图片需先加载图片(利用Image对象);加载完成后再执行操作drawImage(obj,x,y,w,h) 插入图片的坐标宽高等值 <!DOCTYPE html ...
- Linq 单表城市级联
var list = (from province in db.Areas && province.IsDel == join city in db.Areas on province ...
- gpu对任意长度的矢量求和
blockDim.x*gridDim.x 跳过一个grid int <<<参数1,参数2>>>(int *a,int * b,int * c); 如果是一维的,参数 ...
- SQL语句-创建索引
语法:CREATE [索引类型] INDEX 索引名称ON 表名(列名)WITH FILLFACTOR = 填充因子值0~100 GO USE 库名GO IF EXISTS (SELECT * FRO ...
- css学习笔记(2)
----------------|-------------------------|------------------ 标签名 英文全拼 中文 ...
- document.domain
HTML DOM DOCUMENT 对象 定义和用法 domain 属性可返回下载当前文档的服务器域名. 语法 document.domain 说明 该属性是一个只读的字符串,包含了载入当前文档的 w ...