HDOJ4964 Task 贪心

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=4864

分析

贪心,观察数据规模可知,运行时间的优先级高于难度水平。

将机器和任务以此排序,完成一个任务只会对答案贡献一次,因此从收益更高的任务开始尽量完成。

每次为任务选择机器时,选在花费时间满足要求的前提下,难度水平尽可能小的,这样不会更差。

AC代码

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

inline int read() {
	int num = 0;
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9')
		num = num * 10 + c - '0', c = getchar();
	return num;
}

const int maxn = 1e5 + 5, maxy = 105;

struct MT {
	int x, y;

	bool operator < (const MT& rhs) const {
		if (x == rhs.x) return y > rhs.y;
		return x > rhs.x;
	}
} m[maxn], t[maxn];

int a, b, y[maxy];

int main() {
	while (scanf("%d%d", &a, &b) == 2) {
		memset(y, 0, sizeof(y));
		for (int i = 1; i <= a; ++i) m[i].x = read(), m[i].y = read();
		for (int i = 1; i <= b; ++i) t[i].x = read(), t[i].y = read();
		sort(m + 1, m + a + 1), sort(t + 1, t + b + 1);
		int cnt = 0, j = 1;
		long long money = 0;
		for (int i = 1; i <= b; ++i) {
			while (j <= a && m[j].x >= t[i].x) ++y[m[j++].y];
			for (int k = t[i].y; k <= 100; ++k)
				if (y[k]) {
					++cnt, money += 500 * t[i].x + 2 * t[i].y;
					--y[k];
					break;
				}
		}
		printf("%d %lld\n", cnt, money);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值