题意:

  钢铁公司有N个客户的订单,每个订单有一个产量q(生产时间刚好也等于q)和订单完成截止时间。公司要求完成尽量多的订单。

分析:

  先按截止时间d排序,然后维护一个已经选好的订单的优先队列,如果当前无法选择的话,那么尝试和之前花费时间最长的交换。如果qi<qj的话,交换之后花费的时间更短且截止时间di更长。

代码:

  

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

UVA 1153 KEEP THE CUSTOMER SATISFIED的更多相关文章

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

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

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

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

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

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

  4. UVA 1153 Keep the Customer Satisfied 顾客是上帝(贪心)

    因为每增加一个订单,时间是会增加的,所以先按截止时间d排序, 这样的话无论是删除一个订单,或者增加订单,都不会影响已经选好的订单. 然后维护一个已经选好的订单的大根堆(优先队列),如果当前无法选择的话 ...

  5. UVA - 1153 Keep the Customer Satisfied(顾客是上帝)(贪心)

    题意:有n(n<=800000)个工作,已知每个工作需要的时间qi和截止时间di(必须在此之前完成),最多能完成多少个工作?工作只能串行完成.第一项任务开始的时间不早于时刻0. 分析:按截止时间 ...

  6. poj 2786 - Keep the Customer Satisfied

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

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

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

  8. uva 1153 顾客是上帝(贪心)

    uva 1153 顾客是上帝(贪心) 有n个工作,已知每个工作需要的时间q[i]和截止时间d[i](必须在此前完成),最多能完成多少个工作?工作只能串行完成,第一项任务开始的时间不早于时刻0. 这道题 ...

  9. 【习题 8-12 UVA - 1153】Keep the Customer Satisfied

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 结束时间比较早的,就早点开始做. 所以,将n件事情,按照结束时间升序排. 然后对于第i件事情. 尽量把它往左排. 即t+1..t+a ...

随机推荐

  1. Django 从零開始

    1.下载安装django 方法1: pip install Django==1.6.5 測试是否成功安装 : ~$ python import django ~$ (1, 6, 5, 'final', ...

  2. 用Unity做的一个小游戏,仿照一个样例写的,个人认为文章写的不错,哈哈

  3. vlc-android对于通过Live555接收到音视频数据包后的处理分析

    通过ndk-gdb跟踪调试vlc-android来分析从连接到RTSP服务器并接收到音视频数据包后的处理过程. 首先,从前面的文章有分析过vlc-android的处理过程通过线程函数Run()(Src ...

  4. core-site.xml配置项:hadoop.tmp.dir

    hadoop.tmp.dir:A base for other temporary directories. 集群运行后,修改该配置项后,发现类似错误: -- ::, INFO org.apache. ...

  5. C++程序设计实践指导1.2二维数组的操作运算改写要求实现

    改写要求1:改写为以单链表表示二维数组 #include <cstdlib> #include <iostream> using namespace std; struct L ...

  6. 【Android】设备标识简介(imei imsi mac地址)

    IMEI: 1- 意义: 参考http://zh.wikipedia.org/zh-cn/IMEI  国际移动设备辨识码 ,共15位,和厂商,产地等有关. 2- 获取: 直接查看设备信息,设置-关于手 ...

  7. nodejs iconfont处理

    做前端优化,iconfont可以替换掉很多图片,减少请求,并有很好的兼容性,颜色大小也有很好的自由度.现在网上已经有很多公开的iconfont供我们使用.但是每个项目有不同的应用场景,网上的并不能满足 ...

  8. 程序员都会的 35 个 jQuery 小技巧

    收集的35个 jQuery 小技巧/代码片段,可以帮你快速开发. 1. 禁止右键点击 $(document).ready(function(){ $(document).bind("cont ...

  9. Problem 1008 Hay Points

    Problem Description Each employee of a bureaucracy has a job description - a few paragraphs that des ...

  10. MySQL5.7新特性笔记

    001.用户验证方式上的变化 MySQL5.7已经不要支持mysql_old_password验证插件,也不再支持old_password函数,也就说old_passwords也就不能被设置成1了.