Hdu 6000 Wash(贪心)

58 篇文章 0 订阅
15 篇文章 0 订阅

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

思路:

1.首先处理出对于衣服i,其最早洗完时间wash[i],可通过优先队列实现。

2.若保证总完成时间最短,则应优先烘干最后洗完的衣服,与处理最早洗完时间类似,只需按洗完时间从大到小处理,取最大值即可。

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
const int maxn=1e6+50;

struct Node
{
    LL t,tot;
    Node(){}
    Node(LL t,LL tot):t(t),tot(tot){}
    bool operator < (const Node& rhs) const
    {
        return rhs.tot<tot;
    }
};

int l,n,m;
LL wash[maxn];
priority_queue<Node> q;

int main()
{
    int t,cas=0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&l,&n,&m);
        while(!q.empty()) q.pop();
        for(int i=0;i<n;i++)
        {
            LL x;
            scanf("%lld",&x);
            q.push(Node(x,x));
        }
        for(int i=0;i<l;i++)
        {
            Node t=q.top();
            q.pop();
            wash[i]=t.tot;
            q.push(Node(t.t,t.tot+t.t));
        }
        while(!q.empty()) q.pop();
        for(int i=0;i<m;i++)
        {
            LL x;
            scanf("%lld",&x);
            q.push(Node(x,x));
        }
        LL ans=0;
        for(int i=l-1;i>=0;i--)
        {
            Node t=q.top();
            q.pop();
            ans=max(ans,wash[i]+t.tot);
            q.push(Node(t.t,t.tot+t.t));
        }
        printf("Case #%d: %lld\n",++cas,ans);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值