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,问你最多完成多少个工作,每次最多能运行一个工作. 析:这个题是贪心,应该能看出来,关键是贪心策略是什么,这样想,先按截止时间排序, ...
随机推荐
- 微信小程序 WXML、WXSS 和JS介绍及详解
前几天折腾了下.然后列出一些实验结果,供大家参考. 百牛信息技术bainiu.ltd整理发布于博客园 0. 使用开发工具模拟的和真机差异还是比较大的.也建议大家还是真机调试比较靠谱. 1. WXML( ...
- VC++、MFC
VC++.MFC最好的开源项目 介绍:介绍一下用VC++/MFC写的最好的开源项目. Sourceforge.net中有许多高质量的VC++开源项目,我列举了一些可以作为VC++程序员的参考. 正文: ...
- CodeForces 719B Anatoly and Cockroaches (水题贪心)
题意:给定一个序列,让你用最少的操作把它变成交替的,操作有两种,任意交换两种,再就是把一种变成另一种. 析:贪心,策略是分别从br开始和rb开始然后取最优,先交换,交换是最优的,不行再变色. 代码如下 ...
- html行内要素与块级要素
行内要素:在一行里,不可设置width和height,不能上下外铺(margin) span 块状要素,标准的 div
- 洛谷 - P1355 - 神秘大三角 - 简单计算几何
https://www.luogu.org/problemnew/show/P1355 判断一个点和三角形的位置关系,最简单的思路就是用向量. 首先排除掉和三角形顶点重合的情况. 把三角形设计成一个首 ...
- SpringBoot | contrller的使用
@Controller 处理http请求 @RestController Spring4之后新加的注解,原来返回json需要@ResponseBody配合@Controller @RequestMap ...
- win和mac系统Sublime Text 3配置编译c和c++
widows安装 安装MinGW MinGW是Minimalist GNU on Windows的首字母缩写,安装后就可以使用很多的GNU工具.GNU(GNU’s Not Unix)是linux中的一 ...
- AtCoder Grand Contest 005 C - Tree Restoring
题目传送门:https://agc005.contest.atcoder.jp/tasks/agc005_c 题目大意: 给定一个长度为\(N\)的整数序列\(A_i\),问能否构造一个\(N\)个节 ...
- Maximal Area Quadrilateral CodeForces - 340B || 三点坐标求三角形面积
Maximal Area Quadrilateral CodeForces - 340B 三点坐标求三角形面积(可以带正负,表示向量/点的不同相对位置): http://www.cnblogs.com ...
- h5-24-百度地图-地址解析
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...