题意:

n个订单,每个订单有完成需要的天数,和限制的天数,求最多能完成多少订单

分析:

先按限制日期升序排列,若当前订单不能完成,和上面已选中的订单中需要天数中最大的比较,若比它小,则替换他。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
struct node{
int q,d;
}a[];
int n;
bool cmp(node x,node y){
return x.d<y.d;
}
void solve(){
sort(a,a+n,cmp);
int sum=,num=;
priority_queue<int>que;
for(int i=;i<n;++i){
if(sum+a[i].q>a[i].d){
if(que.empty())continue;
int tmp=que.top();
if(tmp>a[i].q){
sum=sum+a[i].q-tmp;
que.pop();
que.push(a[i].q);
}
}
else{
num++;
que.push(a[i].q);
sum+=a[i].q;
}
}
printf("%d\n",num);
}
int main()
{
int t,ca=;
scanf("%d",&t);
while(t--){
if(ca++)
printf("\n");
scanf("%d",&n);
for(int i=;i<n;++i)
scanf("%d%d",&a[i].q,&a[i].d);
solve();
}
return ;
}

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. poj 2786 - Keep the Customer Satisfied

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

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

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

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

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

  5. UVA 1153 KEEP THE CUSTOMER SATISFIED

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

  6. UVALive - 3507 Keep the Customer Satisfied

    题意:收到n个订单,每个订单有q,d分别代表做这个的时间,和最晚的完成时间,问你最多能接受几个订单 思路:贪心,我们显然要按最早的完成时间排序,那么接下来,我们用(6,8)和(4,9)做为例子,按照我 ...

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

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

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

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

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

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

随机推荐

  1. 360抢票 网站维护中 && 你的登录被踢了!

    本来在超市犹豫到底该买哪种暖手袋,犹豫了差不多半个多小时,还没决定好,一看时间还有8分钟到10点,遂狂奔回寝室抢票. 结果,360抢票被12306秒了—— 猜测原因是12306的验证码改了(变成动态的 ...

  2. 【转】Wireshark:“There are no interfaces on which a capture can be done ”

    linux环境下 两种解决方案:    第一种方法:使用root用户登陆        xiaoshancun@xiaoshancun-VM500:~$ sudo wireshark    第二种方法 ...

  3. lintcode:子数组之和为0

    题目: 子数组之和 给定一个整数数组,找到和为零的子数组.你的代码应该返回满足要求的子数组的起始位置和结束位置 样例 给出[-3, 1, 2, -3, 4],返回[0, 2] 或者 [1, 3]. 解 ...

  4. Sina App Engine(SAE)入门教程(2)-Mysql使用

    如果你还没有SAE的账号,请在http://sae.sina.com.cn 注册新用户.具体的注册流程请参见:Sina App Engine(SAE)入门教程(1)在常规的环境下,我们可以通过http ...

  5. 创业草堂之六:CEO的财务自修课

    创业团队中一个最普遍的缺陷,是团队--尤其是团队的核心人物CEO,缺乏基本的财务知识和技能.一个不懂财务知识的CEO,即使业务能力再强,在投资人的眼里,他/她依然是一个笨拙的CEO.粗糙的CEO.鲁莽 ...

  6. Lumina将是基于 Qt工具箱,旨在取代KDE成为PC-BSD默认的桌面环境

    Lumina Desktop 1.1.0 发布了,该版本是重要更新,包括全新的以及完全重新编写的utilities,并对底层基础架构进行改进. Lumina将是基于 Qt工具箱,旨在取代KDE成为PC ...

  7. Tomcat启动后访问首页报错 显示JSP 空指针异常

    HTTP Status 500 - type Exception report message description The server encountered an internal error ...

  8. Javaweb实现的优优图书商城(含源码)

    原文地址:http://www.cnblogs.com/liaoyu/p/uushop.html 源码地址:https://github.com/liaoyu/uushop 贴出一个大学时做的小项目, ...

  9. HDU 3308 线段树 最长连续上升子序列 单点更新 区间查询

    题意: T个测试数据 n个数 q个查询 n个数 ( 下标从0开始) Q u v 查询 [u, v ] 区间最长连续上升子序列 U u v 把u位置改成v #include<iostream> ...

  10. Spring 事务中 readOnly 的解释

      spring 中事务的PROPAGATION_REQUIRED,Readonly的解释  (2012-11-21 16:29:38) 转载▼ 标签:  杂谈                  一. ...