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

    今天是真的萎,切不动题,瞎写陈年老题找自信。。。

    强行一波贪心猛如虎

    先按毁坏时间排序,枚举,能修的就修,修不了就把前面耗时最长的拿出来和当前比较,假如现在需要时间更短就换

    总之就是维护修了ans个的最快时间

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    #include<set>
    using namespace std;
    
    struct node
    {
        int t,ed;
    }a[210000];
    bool cmp(node n1,node n2){return n1.ed<n2.ed;}
    multiset<int> s;
    int main()
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d%d",&a[i].t,&a[i].ed);
        sort(a+1,a+n+1,cmp);
        
        int now=0,ans=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i].t+now<=a[i].ed)
            {
                now+=a[i].t;
                ans++;
                s.insert(a[i].t);
            }
            else
            {
                int q=*--s.end();
                if(a[i].t<q)
                {
                    int sum=s.count(q);
                    s.erase(q);
                    for(int j=1;j<sum;j++)s.insert(q);
                    s.insert(a[i].t);
                    now+=a[i].t-q;
                }
            }
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    sublime text3中html的使用
    WEB如何入门?各种渗透攻击如何入门?
    考思科认证NA过程的学习笔记
    HTML URL 编码(学习笔记)
    学习HTML过程中的笔记
    必学
    playfair密码
    二三级计算机考试时间
    DAY 135 VUE
    DAY 134 RBAC
  • 原文地址:https://www.cnblogs.com/AKCqhzdy/p/8933430.html
Copyright © 2011-2022 走看看