hduoj 6000 && 2016CCPC-final B. Wash(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6000

先求出所有衣服单独洗完的最快时间

再求出所有衣服单独烘干的最快时间

之后两个拼在一起就行了,当然是当前最慢的和当前最快的拼

#include<stdio.h>
#include<queue>
#include<functional>
using namespace std;
#define LL long long
typedef struct Res
{
	LL t, id;
	bool operator < (const Res &b) const
	{
		if(t>b.t)
			return 1;
		return 0;
	}
}Res;
Res now;
priority_queue<Res> q;
LL a[100005], b[100005], t1[1000005], t2[1000005];
int main(void)
{
	LL ans;
	int T, L, n, m, i, cas;
	cas = 1;
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d%d%d", &L, &n, &m);
		for(i=1;i<=n;i++)
			scanf("%lld", &a[i]);
		for(i=1;i<=m;i++)
			scanf("%lld", &b[i]);
		while(q.empty()==0)
			q.pop();
		for(i=1;i<=n;i++)
		{
			now.t = a[i], now.id = i;
			q.push(now);
		}
		for(i=1;i<=L;i++)
		{
			now = q.top();
			q.pop();
			t1[i] = now.t;
			now.t += a[now.id];
			q.push(now);
		}
		while(q.empty()==0)
			q.pop();
		for(i=1;i<=m;i++)
		{
			now.t = b[i], now.id = i;
			q.push(now);
		}
		for(i=1;i<=L;i++)
		{
			now = q.top();
			q.pop();
			t2[i] = now.t;
			now.t += b[now.id];
			q.push(now);
		}
		ans = 0;
		for(i=1;i<=L;i++)
			ans = max(t1[i]+t2[L-i+1], ans);
		printf("Case #%d: %lld\n", cas++, ans);
	}
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值