uva1153 Keep the Customer Satisfied
贪心加优先队列 (默认是小的在前,正好)
//这里又很套路,设队列里的都是符合条件的考虑新加入的即可。再处理一下空队列的情况。很完美//
截止时间短的在前面,干的就多
先根据截止日期排序
优先队列根据完成所需时间排序
首先队列里的都是能完成的
策略:新加入的,如果在前面的完成后仍能完成,就直接加进去;不能,因为截止日期在更后,不影响其他的,比较top元素用的时间,更短就换掉(此时因为截止日期靠后,用的时间还短,所以能成立)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm> using namespace std; const int MAXN = ;
const int N = ; struct order{
int q, d;
bool operator < (const order &a) const {
return q<a.q;
}
}o[MAXN]; int cmp (order a, order b) {
return a.d < b.d;
} int n;
int solve() {
priority_queue<int> done;
int sum = , temp;
for (int i = ; i < n; i++) {
if (o[i].q + sum <= o[i].d) {
done.push(o[i].q);
sum += o[i].q;
}
else if (!done.empty()){
temp = done.top();
if (temp > o[i].q) {
sum = sum - temp + o[i].q;
done.pop();
done.push(o[i].q);
}
}
}
return done.size();
} int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d%d", &o[i].q, &o[i].d);
sort(o, o + n, cmp);
printf("%d\n", solve());
if(T)
printf("\n");
}
return ;
}
uva1153 Keep the Customer Satisfied的更多相关文章
- UVA-1153 Keep the Customer Satisfied (贪心)
题目大意:有n件工作,做每件工作的消耗时间为s,截止时间为d,问最多能做完几件工作. 题目分析:贪心策略:优先做截止时间靠前的,一旦做不完当前工作,则从已经做过的工作中删去一件耗时最长的,用当前工作取 ...
- UVA - 1153 Keep the Customer Satisfied(贪心)
UVA - 1153 Keep the Customer Satisfied Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: ...
- 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 ...
- UVa 1153 Keep the Customer Satisfied 【贪心 优先队列】
题意:给出n个工作,已知每个工作需要的时间last,以及截止时间end,(必须在截止时间之前完成)问最多能够完成多少个工作 首先预处理,将这n件任务按照截止时间从小到大排序 然后用一个cur记录当前做 ...
- Keep the Customer Satisfied
题意: n个订单,每个订单有完成需要的天数,和限制的天数,求最多能完成多少订单 分析: 先按限制日期升序排列,若当前订单不能完成,和上面已选中的订单中需要天数中最大的比较,若比它小,则替换他. #in ...
- UVA 1153 KEEP THE CUSTOMER SATISFIED
题意: 钢铁公司有N个客户的订单,每个订单有一个产量q(生产时间刚好也等于q)和订单完成截止时间.公司要求完成尽量多的订单. 分析: 先按截止时间d排序,然后维护一个已经选好的订单的优先队列,如果当前 ...
- UVALive - 3507 Keep the Customer Satisfied
题意:收到n个订单,每个订单有q,d分别代表做这个的时间,和最晚的完成时间,问你最多能接受几个订单 思路:贪心,我们显然要按最早的完成时间排序,那么接下来,我们用(6,8)和(4,9)做为例子,按照我 ...
- UVa 1153 Keep the Customer Satisfied (贪心+优先队列)
题意:给定 n 个工作,已知每个工作要用的时间 q 和 截止时间 d,问你最多完成多少个工作,每次最多能运行一个工作. 析:这个题是贪心,应该能看出来,关键是贪心策略是什么,这样想,先按截止时间排序, ...
随机推荐
- CF838D Airplane Arrangement
题目描述:https://www.luogu.org/problemnew/show/CF838D(有翻译) (为什么博客园把我刚写的给吞了……orz) 这题当初看的十分懵逼,不过听了肖大佬的做法还是 ...
- thiis also a test
EL表达式 1.EL简介 1)语法结构 ${expression} 2)[]与.运算符 EL 提供.和[]两种运算符来存取数据. 当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号, ...
- ol 与ul 的区别
1 <!DOCTYPE html> <html> <body> <ul> <li>咖啡</li> <li>牛奶< ...
- ubuntu scp命令或者用root连接ssh提示:Permission denied, please try again.错误
1.su - #!!! 2.vi /etc/ssh/sshd_config 3.PermitRootLogin yes # 找到此字段,改为此行所示 4./etc/init.d/ssh restart ...
- Linux2.6 内核中结构体初始化(转载)
转自:http://hnniyan123.blog.chinaunix.net/uid-29917301-id-4989879.html 在Linux2.6版本的内核中,我们经常可以看到下面的结构体的 ...
- PhpStorm之设置字体大小
1.点击左上角的File,再点击setting:(Ctrl+Alt+S) 2.进入 Editor / General,选择 Change font size (Zoom) with Ctrl+Mo ...
- 二分匹配ZOJ3646
//题意:类比线代里:把矩阵中的U看作[1],是否满足一个满秩矩阵 //利用二分匹配就是 //每一行都有相对应的列: #include<iostream> #include<stri ...
- python __builtins__ memoryview类 (46)
46.'memoryview', 返回给定参数的内存查看对象(Momory view).所谓内存查看对象,是指对支持缓冲区协议的数据进行包装,在不需要复制对象基础上允许Python代码访问. cla ...
- vue父组件调用子组件方法
父组件: 代码 <sampleapplylinemodel ref="sampleapplylinemodel" @reLoad="_fetchRecords&qu ...
- LuoguP1268树的重量【构造/思维】By cellur925
题目传送门 Description 给你一个矩阵$M$,$M(i,j)$表示$i$到$j$的最短距离.定义树的重量为树上各边权之和,对于任意给出的合法矩阵$M$,已知它所能表示树的重量是唯一确定的.给 ...