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,问你最多完成多少个工作,每次最多能运行一个工作. 析:这个题是贪心,应该能看出来,关键是贪心策略是什么,这样想,先按截止时间排序, ...
随机推荐
- 51Nod 1327 棋盘游戏 —— 延迟DP
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1327 看博客:https://www.cnblogs.com/Na ...
- input type=password 浏览器会自动填充密码的问题
解决办法是在form上或input上添加autoComplete="off"这个属性. form表单的属性如下所示: 但是这个解决方案在谷歌和火狐上均有bug,下面来一个一个解决. ...
- InstallShield 12 豪华版+破解版 下载
InstallShield 12 豪华版+破解版 下载 2009-07-09 19:18:30| 分类: 默认分类|字号 订阅 InstallShield 12 豪华版+破解版 下载 下载方 ...
- Entity Framework 实体间的外键关系
EF 默认是开户级联删除的,这此规则将会删除非空外键和多对多的关系,如果 在数据库上下文中的实体模型类 存在着 级联引用和多重删除路径,那么EF就抛出 级联引用和多重删除路径的异常. Introduc ...
- 洛谷 - P1309 - 瑞士轮 - 归并排序
https://www.luogu.org/problemnew/show/P1309 一开始写的直接快排没想到真的TLE了. 想到每次比赛每个人前移的量不会很多,但是不知从哪里开始优化. 搜索一下原 ...
- BZOJ2217:Lollipop
题意 给定一个由1和2组成的序列,多次询问是否存在一个区间满足区间和=x 分析 结论:假如存在一个子串和为x,那么一定存在一个前缀,和为x或x+1 证明:可以认为原串是由和为x的串在开头和结尾添加若干 ...
- poj2389 普通的大数乘法
= =.每次这种题目说只有40位 然而要开到100位,心里总是一万匹草泥马在奔腾: #include <iostream> #include <stdio.h> #includ ...
- spring AOP excution表达式各符号意思
execution(*com.sample.service.impl..*.*(..)) 符号 含义 execution() 表达式的主题 第一个“*”符号 表示返回值的类型任意: com.sampl ...
- pip 国内安装镜像源
转自: https://blog.csdn.net/xuezhangjun0121/article/details/81664260 pip国内的一些镜像 阿里云 http://mirrors.a ...
- spring MVC 文件上传错误
1.The request sent by the client was syntactically incorrect () http://luanxiyuan.iteye.com/blog/187 ...