题意:收到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. 详细的Log4j使用教程

    日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供方便的日志记录.在apache网站:jakarta.apache.org/log4j 可以免费下载到Log ...

  2. wapp HTTP Error 404. The requested resource is not found.

    原因: 本地80端口被占用,需要修改WAMP的默认端口 修改设置: 找到 bin/apache/apache***/conf/httpd.conf文件 将文件中的80修改为8088 修改这两个地方端口 ...

  3. C# 中使用正则表达式验证电话号码、手机号、身份证号

    验证电话号码的主要代码如下: public bool IsTelephone(stringstr_telephone) { returnSystem.Text.RegularExpressions.R ...

  4. php中的func_num_args、func_get_arg与func_get_args函数

    From: http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/09/21/2183157.html php的的func_num_args.f ...

  5. 轻松利用WayOs修正版配合推广EasyRadius用户微信公众自助平台

    各大平台争相推出微信公共平台服务,EasyRadius也不会OUT!!! EasyRadius已推出微信公共平台自助服务,用户只需要把公众平台设置为开发者模式,并设置专用的地址,就可以实现旗下宽带用户 ...

  6. spring cloud feign 上传文件报not a type supported by this encoder解决方案

    上传文件调用外部服务报错: not a type supported by this encoder 查看SpringFormEncoder类的源码: public class SpringFormE ...

  7. 条理清晰的搭建SSH环境之整合Struts和Spring

    上文说到搭建SSH环境所需三大框架的jar包,本篇博客将通过修改配置文件整合Struts和Spring,下篇博客整合Hibernate和Spring即可完成环境搭建. 1.声明bean,新建TestA ...

  8. vue路由跳转报错解决

    vue路由跳转: setTimeout(function () { console.log(this); this.$router.push("/login"); },800) 语 ...

  9. zabbix服务端安装指南及常见问题解决

    1. 首先要准备LNMP环境 2. 在mysql中创建zabbix所需要的库和用户 mysql -uroot -pmysql> CREATE DATABASE zabbix CHARACTER ...

  10. c++单例设计模式---17

    原创博文,转载请标明出处--周学伟  http://www.cnblogs.com/zxouxuewei/ 全局变量在项目中是能不用就不用的,它是一个定时炸弹,是一个不安全隐患,特别是在多线程程序中, ...