题意:收到n个订单,每个订单有q,d分别代表做这个的时间,和最晚的完成时间,问你最多能接受几个订单

思路:贪心,我们显然要按最早的完成时间排序,那么接下来,我们用(6,8)和(4,9)做为例子,按照我们的贪心原则我们首先选择(6,8),然后再(4,9),但显然(4,9)作为首选才是最好的选择,试想一下不能两个都选的情况,就是我们总共做的时间4+6>9(第二个的最迟的时间),那么我们要删除做的时间最长的才是最优的

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
const int MAXN = 1000002; struct node{
int q,d;
}arr[MAXN];
int n; bool cmp(node a,node b){
return a.d < b.d;
} int main(){
int t;
scanf("%d",&t);
for (int cas = 0; cas < t; cas++){
if (cas)
printf("\n");
scanf("%d",&n);
for (int i = 0; i < n; i++)
scanf("%d%d",&arr[i].q,&arr[i].d);
sort(arr,arr+n,cmp);
priority_queue<int> Q;
int ans = 0;
for (int i = 0; i < n; i++){
ans += arr[i].q;
Q.push(arr[i].q);
while (ans > arr[i].d){
ans -= Q.top();
Q.pop();
}
}
printf("%d\n",Q.size());
}
return 0;
}

UVALive - 3507 Keep the Customer Satisfied的更多相关文章

  1. UVALive 3507:Keep the Customer Satisfied(贪心 Grade C)

    VJ题目链接 题意: 知道n(n <= 8e6)个工作的完成所需时间q和截止时间d,你一次只能做一个工作.问最多能做多少工作? 思路: 首先很像贪心.观察发现如下两个贪心性质: 1)一定存在一个 ...

  2. UVA - 1153 Keep the Customer Satisfied(贪心)

    UVA - 1153 Keep the Customer Satisfied Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: ...

  3. poj 2786 - Keep the Customer Satisfied

    Description   Simon and Garfunkel Corporation (SG Corp.) is a large steel-making company with thousa ...

  4. UVA1153-Keep the Customer Satisfied(贪心)

    Problem UVA1153-Keep the Customer Satisfied Accept: 222  Submit: 1706Time Limit: 3000 mSec Problem D ...

  5. UVa 1153 Keep the Customer Satisfied 【贪心 优先队列】

    题意:给出n个工作,已知每个工作需要的时间last,以及截止时间end,(必须在截止时间之前完成)问最多能够完成多少个工作 首先预处理,将这n件任务按照截止时间从小到大排序 然后用一个cur记录当前做 ...

  6. Keep the Customer Satisfied

    题意: n个订单,每个订单有完成需要的天数,和限制的天数,求最多能完成多少订单 分析: 先按限制日期升序排列,若当前订单不能完成,和上面已选中的订单中需要天数中最大的比较,若比它小,则替换他. #in ...

  7. UVA 1153 KEEP THE CUSTOMER SATISFIED

    题意: 钢铁公司有N个客户的订单,每个订单有一个产量q(生产时间刚好也等于q)和订单完成截止时间.公司要求完成尽量多的订单. 分析: 先按截止时间d排序,然后维护一个已经选好的订单的优先队列,如果当前 ...

  8. UVA-1153 Keep the Customer Satisfied (贪心)

    题目大意:有n件工作,做每件工作的消耗时间为s,截止时间为d,问最多能做完几件工作. 题目分析:贪心策略:优先做截止时间靠前的,一旦做不完当前工作,则从已经做过的工作中删去一件耗时最长的,用当前工作取 ...

  9. UVa 1153 Keep the Customer Satisfied (贪心+优先队列)

    题意:给定 n 个工作,已知每个工作要用的时间 q 和 截止时间 d,问你最多完成多少个工作,每次最多能运行一个工作. 析:这个题是贪心,应该能看出来,关键是贪心策略是什么,这样想,先按截止时间排序, ...

随机推荐

  1. unity-------Light的各个参数使用

    网上看到一篇关于灯光的文章,描述的很详细,如下: Lights will bring personality and flavor to your game. You use lights to il ...

  2. 学习TensorFlow的tf.concat使用

    https://www.tensorflow.org/api_docs/python/tf/concat

  3. php脚本超时 结束执行代码

    函数:stream_context_create ,file_get_content 创建并返回一个文本数据流并应用各种选项,可用于fopen(),file_get_contents()等过程的超时设 ...

  4. UNIX环境编程学习笔记(1):——出错处理errno

    lienhua342014 年 8 月 24 日 1. errno变量 文件 <errno.h> 中定义了符号 errno 以及可以赋予它的各种常量,这些常量都是以字符 E 开头.例如,若 ...

  5. flask with gae开发小结

    最近因为要重写之前发布在GAE上的一个博客,又回顾了一下python,同时,因为用的flask,gae等等,一道写一些小总结,供日后查阅. 1, slugify 其实这个问题可以不考虑,只要你愿意用中 ...

  6. Spring MVC异常处理详解 ExceptionHandler good

    @ControllerAdvice(basePackageClasses = AcmeController.class) public class AcmeControllerAdvice exten ...

  7. Android SDK Content loader has encountered a problem” “parseSdkContent Failed ”

    昨天做了一个Android的小程序,调试的时候连接真实的手机,而不是用模拟器.今天早上打开eclipse的时候报错:“Android SDK Content loader has encountere ...

  8. Unity3d开发“类三消”游戏

    新建一个Project,导入图片素材和声音文件,把图片的Texture Type都修改为Sprite(2D and UI)[1].新建一个命名为Background的GameObject,为之添加背景 ...

  9. PDCA 价值所在

    企业IT服务管理实施 不提倡一步到位 对企业IT部门来说,实施ITIL Service Support(服务支持)的意义在于清晰梳理日常IT运维管理过程中遇到的各种各样的事,使IT运维过程变得有序连贯 ...

  10. manifest.json文件介绍

    { // 必须 "manifest_version": 2, // 清单文件的版本,这个必须写,而且必须是2 "name": "My Extensio ...