首页 > Web开发 > 详细

[JSOI2007]建筑抢修

时间:2018-10-25 21:32:15      阅读:158      评论:0      收藏:0      [点我收藏+]

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\n", ans);
}

}  // namespace wyx

int main() {
    wyx::main();
    return 0;
}

[JSOI2007]建筑抢修

原文:https://www.cnblogs.com/wyxwyx/p/bzoj1029.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!