题意:给出n个工作,已知每个工作需要的时间last,以及截止时间end,(必须在截止时间之前完成)问最多能够完成多少个工作

首先预处理,将这n件任务按照截止时间从小到大排序

然后用一个cur记录当前做任务花费的时间, 如果发现当前cur>a[i].end,那么就将队列里面目前最大的last删除,把这个a[i].last加入队列

可以这样想,把更小的放进去,那么可以为后面的任务腾出更多的时间

然后每删除一次队列里面的元素(即不做这个任务),ans++, 最后能够完成的任务就是n-ans

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#define mod=1e9+7;
using namespace std; typedef long long LL;
const int maxn=; struct node{
int last,end;
} a[maxn]; int cmp(node n1,node n2){
return n1.end<n2.end;
} int main(){
int t,n,i,j,cur,ans;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=;i<n;i++) scanf("%d %d",&a[i].last,&a[i].end);
sort(a,a+n,cmp);
priority_queue<int> pq; cur=;
ans=;
for(i=;i<n;i++){
cur+=a[i].last;
pq.push(a[i].last);
if(cur>a[i].end){
cur-=pq.top();
pq.pop();
ans++;
}
}
printf("%d\n",n-ans);
if(t) printf("\n");
}
return ;
}

话说还是看的题解= = 因为自己想成了今年暑假不AC那样的,求最大数量的不相交的题目 是这样转化的,用每一个end-last作为区间的左端点,end作为右端点来做 这样就转化成了求n个区间里面不相交的区间数量

可是 为什么它非得在end-last那一天开始做那件任务呢= =

只需要在截止的时间之前把任务做了就行啦,不一定非得恰好到截止时间才来做 所以这样想就不对啦= =

go---go---go--

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

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

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

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

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

  5. UVA 1153 KEEP THE CUSTOMER SATISFIED

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

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

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

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

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

  8. UVA 11134 - Fabled Rooks(贪心+优先队列)

    We would like to place  n  rooks, 1 ≤  n  ≤ 5000, on a  n×n  board subject to the following restrict ...

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

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

随机推荐

  1. windows 2008 怎么对外开放端口

    服务器已经运行了程序,但是android客户端连接不上, 网上提示说用: start /min telnet 192.168.3.42 2121 查看,但是我的提示tenlet找不到命令,估计是端口的 ...

  2. sqlserver 动态表名 动态字段名 执行 动态sql

    动态语句基本语法: 1 :普通SQL语句可以用exec执行 Select * from tableName exec('select * from tableName') exec sp_execut ...

  3. Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca

    题目链接: http://codeforces.com/contest/575/problem/B 题解: 把链u,v拆成u,lca(u,v)和v,lca(u,v)(v,lca(u,v)是倒过来的). ...

  4. 剑指offer--面试题14

    #include "stdafx.h" #include <iostream> using namespace std; //调整数组顺序使奇数位于偶数前 void O ...

  5. Codeforces Round #363 (Div. 2)->C. Vacations

    C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  6. Codeforces Round #363 (Div. 2)->B. One Bomb

    B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  7. POJ 1191 棋盘分割(DP)

    题目链接 题意 : 中文题不详述. 思路 : 黑书上116页讲的很详细.不过你需要在之前预处理一下面积,那样的话之后列式子比较方便一些. 先把均方差那个公式变形, 另X表示x的平均值,两边平方得 平均 ...

  8. Ubuntu 启动栏添加eclipse图标

    sudo gedit /usr/share/applications/eclipse.desktop [Desktop Entry] Name=Eclipse Comment=c project ma ...

  9. 套题T3

    秋实大哥与线段树 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  10. 欧拉工程第67题:Maximum path sum II

    By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma ...