其他分享
首页 > 其他分享> > 「NOIP2011」观光公交

「NOIP2011」观光公交

作者:互联网

传送门
Luogu

解题思路

有点麻烦,幸好 \(O(n^2)\) 能过。。。
贪心地想一想,我们如果要用加速器,肯定是要选择车上人数最多的时段加速。
但是我们就会面临这样的情况:

那么我们就分类讨论一下,预处理一些东西:
每个站的下车人数,需要更新的车到站时间,每个站的最后一个下车人数。
然后随便搞一下就好了。

细节注意事项

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
    s = 0; int f = 0; char c = getchar();
    while (!isdigit(c)) f |= c == '-', c = getchar();
    while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
    s = f ? -s : s;
}

const int _ = 1010;
const int __ = 10010;

int n, m, k, d[_];
int off[_], arr[_], las[_];
int t[__], a[__], b[__];

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
#endif
    read(n), read(m), read(k);
    for (rg int i = 1; i <= n - 1; ++i) read(d[i]);
    for (rg int i = 1; i <= m; ++i) {
        read(t[i]), read(a[i]), read(b[i]);
        ++off[b[i]], las[a[i]] = max(las[a[i]], t[i]);
    }
    arr[1] = 0;
    for (rg int i = 2; i <= n; ++i)
        arr[i] = max(arr[i - 1], las[i - 1]) + d[i - 1];
    while (k--) {
        int tmp = 0, pos;
        for (rg int i = 2; i <= n; ++i) {
            if (!d[i - 1]) continue;
            int _tmp = 0;
            for (rg int j = i; j <= n; ++j) {
                _tmp += off[j]; if (arr[j] <= las[j]) break;
            }
            if (tmp < _tmp)
                tmp = _tmp, pos = i;
        }
        --d[pos - 1];
        for (rg int i = pos; i <= n; ++i) {
            --arr[i]; if (arr[i] < las[i]) break;
        }
    }
    int ans = 0;
    for (rg int i = 1; i <= m; ++i)
        ans += arr[b[i]] - t[i];
    printf("%d\n", ans);
    return 0;
}

完结撒花 \(qwq\)

标签:__,公交,const,NOIP2011,int,观光,read,include,getchar
来源: https://www.cnblogs.com/zsbzsb/p/11751409.html