Luogu2751 [USACO Training4.2]工序安排Job Processing

Posted xcysblog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
", maxans);
	return 0;
}

以上是关于Luogu2751 [USACO Training4.2]工序安排Job Processing的主要内容,如果未能解决你的问题,请参考以下文章

USACO Training完结感想

Usaco Training [1.3] wormhole

USACO Training Section 3.3 Shopping Offers

USACO Training Section3.1 Score Inflation

回文检测 [USACO Training Section 1.3]

USACO Training Section 1.1 题解(共4题)