UVA 1153 Keep the Customer Satisfied 顾客是上帝(贪心)
因为每增加一个订单,时间是会增加的,所以先按截止时间d排序,
这样的话无论是删除一个订单,或者增加订单,都不会影响已经选好的订单。
然后维护一个已经选好的订单的大根堆(优先队列),如果当前无法选择的话,
那么尝试和之前花费时间最长的交换。如果qi<qj的话,交换之后花费的时间更短且截止时间di更长,情况不会比没交换更糟·。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 8e5+;
struct Cus
{
int q,d;
bool operator < (const Cus& x) const {
return q < x.q;
}
}P[maxn]; bool cmp(const Cus& x, const Cus& y) { return x.d < y.d; }
priority_queue<Cus> Q; int main()
{
//freopen("in.txt","r",stdin);
int T; scanf("%d",&T);
while(T--){
int n; scanf("%d",&n);
for(int i = ; i < n; i++)
scanf("%d%d",&P[i].q,&P[i].d);
sort(P,P+n,cmp);
int cur = ;
for(int i = ; i < n; i++){
if(P[i].q + cur <= P[i].d) Q.push(P[i]), cur += P[i].q;
else {
if(Q.size() && P[i].q < Q.top().q ) {
cur += P[i].q - Q.top().q;
Q.pop(); Q.push(P[i]);
}
}
}
printf("%d\n",Q.size());
while(Q.size()) Q.pop();
if(T) putchar('\n');
}
return ;
}
UVA 1153 Keep the Customer Satisfied 顾客是上帝(贪心)的更多相关文章
- UVA - 1153 Keep the Customer Satisfied(贪心)
UVA - 1153 Keep the Customer Satisfied Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: ...
- UVA - 1153 Keep the Customer Satisfied(顾客是上帝)(贪心)
题意:有n(n<=800000)个工作,已知每个工作需要的时间qi和截止时间di(必须在此之前完成),最多能完成多少个工作?工作只能串行完成.第一项任务开始的时间不早于时刻0. 分析:按截止时间 ...
- UVa 1153 Keep the Customer Satisfied 【贪心 优先队列】
题意:给出n个工作,已知每个工作需要的时间last,以及截止时间end,(必须在截止时间之前完成)问最多能够完成多少个工作 首先预处理,将这n件任务按照截止时间从小到大排序 然后用一个cur记录当前做 ...
- UVA 1153 KEEP THE CUSTOMER SATISFIED
题意: 钢铁公司有N个客户的订单,每个订单有一个产量q(生产时间刚好也等于q)和订单完成截止时间.公司要求完成尽量多的订单. 分析: 先按截止时间d排序,然后维护一个已经选好的订单的优先队列,如果当前 ...
- UVa 1153 Keep the Customer Satisfied (贪心+优先队列)
题意:给定 n 个工作,已知每个工作要用的时间 q 和 截止时间 d,问你最多完成多少个工作,每次最多能运行一个工作. 析:这个题是贪心,应该能看出来,关键是贪心策略是什么,这样想,先按截止时间排序, ...
- 【uva 1153】Keep the Customer Satisfied(算法效率--贪心+优先队列)
题意:有N个工作,已知每个工作需要的时间和截止时间.要求所有工作穿行完成,第一项任务开始的时间不早于时刻0.问最多能完成多少个工作.(N≤800000) 解法:贪心.可以模型化题目为:已知N个任务的长 ...
- uva 1153 顾客是上帝(贪心)
uva 1153 顾客是上帝(贪心) 有n个工作,已知每个工作需要的时间q[i]和截止时间d[i](必须在此前完成),最多能完成多少个工作?工作只能串行完成,第一项任务开始的时间不早于时刻0. 这道题 ...
- poj 2786 - Keep the Customer Satisfied
Description Simon and Garfunkel Corporation (SG Corp.) is a large steel-making company with thousa ...
- UVA1153-Keep the Customer Satisfied(贪心)
Problem UVA1153-Keep the Customer Satisfied Accept: 222 Submit: 1706Time Limit: 3000 mSec Problem D ...
随机推荐
- 解决错误---undefined reference to `pthread_create‘
今天试着敲了一下APUE的小例子,遇到了个错误 ----- undefined reference to `pthread_create.(为自己这么晚接触多线程惭愧). 上网上查了一下,借人经验. ...
- 【Java】NIO中Channel的注册源码分析
Channel的注册是在SelectableChannel中定义的: public abstract SelectionKey register(Selector sel, int ops, Obje ...
- 分层确定性钱包开发的代码实现(HD钱包服务)
HD Wallets的全称是Hierachical Deterministic Wallets, 对应中文是 分层确定性钱包. 这种钱包能够使用一组助记词来管理所有的账户的所有币种,在比特币的BIP3 ...
- 2017 Fzu校赛 [Cloned]
A - Salty Fish 海边躺着一排咸鱼,一些有梦想的咸鱼成功翻身(然而没有什么卵用),一些则是继续当咸鱼.一个善良的渔夫想要帮这些咸鱼翻身,但是渔夫比较懒,所以只会从某只咸鱼开始,往一个方向, ...
- 遍历问题 codevs
1029 遍历问题 1029 遍历问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 我们都很熟悉二叉树的前序.中序. ...
- 浅谈css常用伪类用法
着重写一下after和before的用法: css样式搞定:标签元素+伪类after a.'class名':after{//我的样式名称是这个,可以写成你自己的样式名称 content: '已打包'; ...
- C.One Piece
链接:https://ac.nowcoder.com/acm/contest/908/C 题意: Luffy once saw a particularly delicious food, but h ...
- Hive_Hive的数据模型_分区表
Hive的数据模型之分区表 准备数据表: create table sampledata (sid int, sname string, gender string, language int, ma ...
- Jmeter4.0----cookie(8)
1.说明 在脚本编写的过程中,我们常常会遇到用户登录的情况,并且将部分重要信息保存在用户的cookie中,所以,来说一下,对用户登录产生cookie的操作情况. 2.步骤 第一步:添加HTTP Coo ...
- 转 MySQL权限管理
###sample: #####view all userSELECT user, host from mysql.user;mysql> SELECT user, host from mysq ...