Wash HDU - 6000 贪心

题目链接:
HDU-6000 Wash

大意:
和洗衣服需要不同代价的贪心题有点类似,貌似以前做过
有 L 件衣服, n 个洗衣机,m个烘干机
给出洗衣机和烘干机时间 a i , b i .
求最短时间

分析:
给洗衣机和烘干机排序,分别需要用到两个 pii 优先队列

first存储当前时间(now),second存储原先需要的时间(base)

贪心策略:洗衣机时间短的先洗
先对洗衣机进行排序,得到第 i 件衣服的时间,记为 c i
策略:
时间长的先烘干,时间慢的后烘干,即从后往前枚举 c i
具体实现;

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
using namespace std;
#define pb push_back
#define inf (1e9+10)
#define mem(s,t) memset(s,t,sizeof s)
typedef long long ll;
typedef pair<ll,ll> pii;

const ll MAXN =1e6+10;
int main() {
    ll T;
    scanf("%lld",&T);
    ll kase=1;  
    while(T--){
        ll l,n,m;
        scanf("%lld%lld%lld",&l,&n,&m);
        priority_queue<pii,vector<pii>,greater<pii> > q1,q2;
        for(ll i=0;i<n;i++){
            ll x;
            scanf("%lld",&x);
            q1.push(make_pair(x,x));
        }
        for(ll j=0;j<m;j++){
            ll x;
            scanf("%lld",&x);
            q2.push(make_pair(x,x));
        }
        ll ret[MAXN];
        for(ll i=0;i<l;i++){
            pii t=q1.top();
            q1.pop();
            ret[i]=t.first;
            q1.push(make_pair(t.first+t.second,t.second));
        }
        ll ans=0;
        for(ll i=l-1;i>=0;i--){
            pii t=q2.top();
            q2.pop();
            ans=max(ans,t.first+ret[i]);
            q2.push(make_pair(t.first+t.second,t.second));
        }
        cout<<"Case #"<<kase++<<": "<<ans<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/joovo/article/details/79211513