「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
", ans);
	return 0;
}

完结撒花 (qwq)

原文地址:https://www.cnblogs.com/zsbzsb/p/11751409.html