Luogu2751 [USACO Training4.2]工序安排Job Processing
你怎么搞他时间都是一样的,考虑贪心
计算第一轮的时间就直接拿堆维护每个机器的结束时间,
每次取最早的,更新每个物品的答案
考虑第二轮,每次取上轮结束时间最晚的放到结束时间最早的机器里
这样一定是最优的
由于 a 类机器和 b 类机器是分开工作的,所以就直接这样贪心就好了
代码:
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cctype> #include <cstdio> #include <queue> using namespace std; const int MAXN = 1005, MAXM = 35; struct Node{ int tim, len; bool operator < (const Node& b) const { return tim > b.tim; } }a[MAXM], b[MAXM]; int n, ma, mb, maxans; int fa[MAXN], fb[MAXN]; priority_queue<Node> q; int main() { scanf("%d%d%d", &n, &ma, &mb); for (int i = 1; i <= ma; ++i) { scanf("%d", &a[i].len); a[i].tim = a[i].len; q.push(a[i]); } for (int i = 1; i <= mb; ++i) { scanf("%d", &b[i].len); b[i].tim = b[i].len; } for (int i = 1; i <= n; ++i) { Node tmp = q.top(); q.pop(); fa[i] = tmp.tim; tmp.tim += tmp.len; q.push(tmp); } printf("%d ", fa[n]); while (q.size()) q.pop(); for (int i = 1; i <= mb; ++i) q.push(b[i]); for (int i = n; i >= 1; --i) { Node tmp = q.top(); q.pop(); maxans = max(maxans, fb[i] = fa[i] + tmp.tim); tmp.tim += tmp.len; q.push(tmp); } printf("%d\n", maxans); return 0; }
禁止诸如开发者知识库/布布扣/码迷/学步园/马开东等 copy 他人博文乃至博客的网站转载
,用户转载请注明出处:https://www.cnblogs.com/xcysblog/