zoukankan      html  css  js  c++  java
  • 【bzoj1029】[JSOI2007]建筑抢修

    按照t2从小到大排列之后贪心。
    若当前任务可以插入,则插入。
    若当前任务不可以插入,分两种情况:
    ①当前任务的耗时大于等于之前插入的任务的最大耗时:跳过当前任务
    ②当前任务的耗时小于之前插入的任务的耗时:将最前插入的耗时最大的那个任务删除,插入当前任务
    用堆维护
     
    #include<algorithm>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    #include<queue>
    using namespace std;
     
    #define MAXN 150010
     
    priority_queue<int>q;
     
    int n;
    int i;
    int res,ans,tmp;
     
    struct Node
    {
        int t,d;
    }a[MAXN];
     
    int cmp(Node x,Node y)
    {
        return x.d<y.d;
    }
     
    int main()
    {
        scanf("%d",&n);
        for (i=1;i<=n;i++)
            scanf("%d%d",&a[i].t,&a[i].d);
        sort(a+1,a+n+1,cmp);
        for (i=1;i<=n;i++)
            if (res+a[i].t<=a[i].d)
            {
                ans++;
                res+=a[i].t;
                q.push(a[i].t);
            }
            else
            {
                tmp=q.top();
                if (a[i].t<tmp)
                {
                    q.pop();
                    q.push(a[i].t);
                    res+=a[i].t-tmp;
                }
            }
        printf("%d",ans);
        return 0;
    }
    

      

  • 相关阅读:
    Spring学习之旅(二)--容器
    Spring学习之旅(一)--初始Spring
    Logback的使用
    DES加解密工具类
    Lombok插件的使用
    from 表单用 GET 方法进行 URL 传值时后台无法获取问题
    组播
    linux头文件路径
    IANA
    6号板获取或放文件
  • 原文地址:https://www.cnblogs.com/yangjiyuan/p/5321105.html
Copyright © 2011-2022 走看看