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 ...
随机推荐
- FZU - 2214 Knapsack problem 01背包逆思维
Knapsack problem Given a set of n items, each with a weight w[i] and a value v[i], determine a way t ...
- iOS有用的三方库和高效工具记录
DKNightVersion https://github.com/Draveness/DKNightVersion#podfile 用来为APP添加夜间模式和换肤功能
- 315. Count of Smaller Numbers After Self(Fenwick Tree)
You are given an integer array nums and you have to return a new counts array. The counts array has ...
- django 数据库建表流程,与表结构
目录 配置数据库 创建表结构 多表关连的设置 自创建关联表方法 自建表 和 ManyToManyField 联合使用 配置数据库 在Django项目的settings.py文件中,配置数据库连接信息: ...
- 第九组 通信3班 063 OSPFv2与OSPFv3综合实验
实验目的 1. 掌握 OSPFv3(v2) 的配置方法 2. 掌握在帧中继环境下 OSPFv3 (v2)的配置方法 3. 掌握 OSPFv3(v2) NSSA 的配置方法 4. 掌握外部路由汇总的配置 ...
- Corn Fields(模板)
题目链接 #include <stdio.h> #include <algorithm> #include <string.h> #include <iost ...
- Python面向对象之类和实例
1.类的定义 定义是用过class关键字 class Student(object): pass class 后面紧接着是类名,即Student,类名通常是大写开头的单词, 紧接着是(object), ...
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...
- 常见的HTTP状态码说明
1.说明 HTTP服务器状态代码定义(Status Code Definitions) 做测试的时候,会产生比较多的HTTP错误,查看其错误,有超时的,链接不到图片的,连接不到服务器等等,很多人经常忘 ...
- Datagridview强制结束编辑状态
DirectCast(dgvTab1.CurrentRow.DataBoundItem, DataRowView).EndEdit() dgvTab1.CommitEdit(DataGridViewD ...