zoukankan      html  css  js  c++  java
  • [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;
    }
    
  • 相关阅读:
    JS中的this指向问题
    Jinja2用法总结
    Kafka 生产者 拦截器
    Kafka 生产者 工作流程和Demo示例
    Kafka 验证集群部署和吞吐量测试
    Kafka 线上环境部署需要考虑的因素
    Kafka单点环境安装
    Kafka和Confluent的关系
    Kafka 概要设计
    ActiveMQ 介绍安装使用入门
  • 原文地址:https://www.cnblogs.com/wyxwyx/p/bzoj1029.html
Copyright © 2011-2022 走看看