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件商品,中午的时候会有顾客需要购买 ...
随机推荐
- Linux 进程与线程五
pthread_self函数 pthread_t pthread_self(void); 一般会成功,返回当前线程的ID 注意:在子线程中执行exit()函数会退出整个进程,一般使用pthread_e ...
- 微信H5中的一些坑
最近在写微信公众号H5页面 遇到了一些坑,在这里记录一下 记录一下signature的计算 // 首先找到hex_sha1的加密算法,ticket 是后端提供的 var url_local = loc ...
- [LeetCode] Trapping Rain Water II 收集雨水之二
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...
- IT培训行业揭秘(四)
IT培训班的老师前面已经说过,很多都是从一线程序员岗位转过来的,因为培训行业的收入整体上来看还是比作普通程序员要高一些,这是市场的普遍行情.还有一部分老师从培训班学习过并且留到培训班任教的.一般这种老 ...
- Mysql基本语句的总结
1---------------创建一个表------------------------------------ drop table if exists 表名 create table 表名( ...
- IOS跑马灯效果,实现文字水平无间断滚动
ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController{ NSTimer ...
- openssl+前端jsrsa签名+后端nodejs验签
内容如标题所示,总体分为三个部分: 一.win10下安装openssl,然后通过openssl工具生成RSA的公钥和私钥 (1)win10下安装openssl需要的工具有:VS2013,Perl,na ...
- 测试对于list的sort与sorted的效率
sorted from time import clock from random import randint start = clock() a = [randint(0,1000000) for ...
- jQuery实现动态分割
由jQuery实现上下.左右动态改变左右.上下两个div的大小,需要自己引入jquery1.8.0.min.js包 可用于页面布局. //============================ind ...
- 【BZOJ 2595】【WC 2008】游览计划
http://www.lydsy.com/JudgeOnline/problem.php?id=2595 斯坦纳树的例题诶...我怎么做了好长时间_(:з」∠)_ 首先这是一棵树. 状压表示状态,\( ...