UPC 6910 洗衣服

题目描述

你现在要洗L件衣服。你有n台洗衣机和m台烘干机。由于你的机器非常的小,因此你每次只能洗涤(烘干)一件衣服。
第i台洗衣机洗一件衣服需要wi分钟,第i台烘干机烘干一件衣服需要di分钟。请问把所有衣服洗干净并烘干,最少需要多少时间?假设衣服在机器间转移不需要时间,并且洗完的衣服可以过一会再烘干。

输入

输入第一行有3个整数L,n和m。第二行有n个整数w1,w2,...,wn。第三行有m个整数d1,d2,...,dm。

输出

输出一行一个整数,表示所需的最少时间。

样例输入

1 1 1
1200
34

样例输出

1234

题目意思就像题目说的,思路为,对于洗衣机,肯定是每次找结束时间最靠前的那个来洗。对于烘干机,我们仍然可以将其看作是洗衣机,对于每件衣服我们 , 其实我们可以当成是一个匹配,每一个洗衣机可以匹配一个烘干机,那么这一个时间就是两个时间之和,这个匹配的里面的最大值就是答案, 所以我们需要的就是那个最大值, 所以我们要尽可能是这个最大值最小,所以我们可以拿最大的去匹配最小的,一次匹配,就是答案了,感觉像是二分图,但是又不事,那么答案就是max(a[i]+b[L-i+1])。

AC代码:

#include<stdio.h>
#include<iostream>
#include<queue>
#define LL long long
#define p pair<LL, LL>
#define M 1000000000000000
using namespace std;
const int maxn = 1e6 + 10;
priority_queue<p, vector<p>, greater<p> >q;
LL a[maxn], b[maxn];
int main()
{
    int L, n, m;
    cin >> L >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        LL x;
        cin >> x;
        q.push(make_pair(x, x));
    }
    for(int i = 1; i <= L; i++)
    {
        p tmp = q.top();
        a[i] = tmp.first;
        q.pop();
        q.push(make_pair(tmp.first+tmp.second, tmp.second));
    }
    while(!q.empty()) q.pop();
    for(int i = 1; i <= m; i++)
    {
        LL x;
        cin >> x;
        q.push(make_pair(x, x));
    }
    LL ans = 0;
    for(int i = 1;  i <= L; i++)
    {
        p tmp = q.top();
        b[i] = tmp.first;
        q.pop();
        q.push(make_pair(tmp.first+tmp.second, tmp.second));
    }
    /*
    for(int i = L; i >= 1; i--)
    {
        p tmp = q.top();
        q.pop();
        ans = max(ans, a[i]+tmp.first);
        q.push(make_pair(tmp.first+tmp.second, tmp.second));
    }
    */
    for(int i = 1; i <= L; i++)
    {
        ans = max(ans, a[i]+b[L-i+1]);
    }
    cout << ans << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/MALONG11124/article/details/81558658
UPC