Hdu 6000 Wash(貪心)

題目地址: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;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章