• [JSOI2007]建筑抢修


    Description

    BZOJ1029

    Solution

    这个题猫锟讲过我还不会……

    就是按着deadline排一下序,先做能做的,如果一个东西做不了,那就把他和之前做的用时最长的换一下,这样总用时会少,也不影响其他的任务,何乐而不为呢。

    Code

    #include <algorithm>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <vector>
    
    namespace wyx {
    
    #define ll long long
    
    ll read() {
        ll ans = 0, fl = 1;
        char c = getchar();
        while (c < '0' || c > '9') {
            if (c == '-') fl = -1;
            c = getchar();
        }
        ans = c - '0';
        for (c = getchar(); c >= '0' && c <= '9'; c = getchar())
            ans = ans * 10 + c - '0';
        return ans * fl;
    }
    
    #define pi std::pair<ll, ll>
    #define dl first
    #define tm second
    
    const int N = 150010;
    const int ha = 10000;
    
    pi a[N];
    std::priority_queue<ll> q;
    int n;
    
    void main() {
        n = read();
        for (int i = 1; i <= n; ++i) a[i].tm = read(), a[i].dl = read();
        std::sort(a + 1, a + n + 1);
        ll nw = 0, ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (nw + a[i].tm <= a[i].dl)
                nw += a[i].tm, ans++, q.push(a[i].tm);  // 这里还忘入队了……
            else if (!q.empty()) {
                ll u = q.top();
                if (u > a[i].tm) {  // 贪心写反了……
                    q.pop();
                    q.push(a[i].tm);
                    nw -= u - a[i].tm;
                }
            }
        }
        printf("%lld
    ", ans);
    }
    
    }  // namespace wyx
    
    int main() {
        wyx::main();
        return 0;
    }
    
  • 相关阅读:
    Navicat For SQL Server 修改字段为自增主键
    navicat for sql server 12下载地址
    git 同时关联多个远程库
    Mysql general_log 日志详解
    angular教程
    Python代码写好了怎么运行?
    python mysql自增字段AUTO_INCREMENT值的修改方式
    Python自学教材推荐 初学者必看
    永久性差异
    如何关闭搜狗的流氓弹窗广告
  • 原文地址:https://www.cnblogs.com/wyxwyx/p/bzoj1029.html
Copyright © 2020-2023  润新知