1. 程式人生 > >HDU 6000 - Wash

HDU 6000 - Wash

return light std emp 分析 for cpp c++ scanf

/*
HDU 6000 - Wash [ 貪心 ]
題意:
	L 件衣服,N 個洗衣機,M 個烘幹機,給出每個洗衣機洗一件衣服的時間和烘幹機烘幹一件衣服的時間,問需要的最少時間是多少
分析:
	先求出L件衣服最優洗衣時間的數組,再求出最優烘幹時間的數組
	然後排序按最小值+最大值的思路貪心,取最大值
	可以看成排序後兩數組咬合
*/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 1e5+5;
const int MAXL = 1e6+5;
struct Node {
    LL x; int y;
    friend operator < (Node a, Node b) {
        if (a.x == b.x) return a.y > b.y;
        return a.x > b.x;
    }
};
priority_queue<Node> Q;
int t, l, n, m;
int w[N], d[N];
LL a[MAXL], b[MAXL];
void solve(int w[], int n, LL a[])
{
    while (!Q.empty()) Q.pop();
    for (int i = 1; i <= n; i++) Q.push(Node{w[i], w[i]});
    for (int i = 1; i <= l; i++)
    {
        Node tmp = Q.top(); Q.pop();
        a[i] = tmp.x;
        tmp.x += tmp.y;
        Q.push(tmp);
    }
}
int main()
{
    scanf("%d", &t);
    for (int tt = 1; tt <= t; tt++)
    {
        scanf("%d%d%d", &l, &n, &m);
        for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
        for (int i = 1; i <= m; i++) scanf("%d", &d[i]);
        solve(w, n, a);
        solve(d, m, b);
        LL ans = 0;
        for (int i = 1; i <= l; i++)
        {
            ans = max(ans, a[i] + b[l-i+1]);
        }
        printf("Case #%d: %lld\n", tt, ans);
    }
}

  

HDU 6000 - Wash