Bzoj 5088 HDU 6000 Upc6910 Wash(洗衣服)这辈子都学不会的贪心+优先队列

题目链接:BZOJ : https://www.lydsy.com/JudgeOnline/problem.php?id=5088

                   Hdu :   http://acm.hdu.edu.cn/showproblem.php?pid=6000

题目描述

你现在要洗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

提示

题意:中文题意不多BB;但是这个真的是没想到竟然可以这样贪心,可以这样玩。就是考虑洗衣机,每次最早在啥时候用,先对洗衣机排个序,然后每次选出来一个,然后记录下时间,再把当前洗衣机加上运行的时间放进去,考虑下次用到这个洗衣服的最早时间。就这样选出来 l 个就就好了。对于烘干的话,倒着考虑,就是最后一个往前每一个都尽量少的时间,因为考虑一种情况假如洗的很快但是却烘干的很慢也是等着。所以从后往前的时候考虑烘干最快,这样就可以减少结束的时间,不懂的话自己模拟下多道程序进行,要的时间肯定是所有任务都结束的时间,所以尽可能让最后结束的那个时间短点,最后的时间等于max某个点的结束时间。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
int b[100005];
ll Atime[1000005];
struct node{
    ll delin;
    int id;
};
bool operator <(node a,node b)
{
    return a.delin > b.delin; 
}
int main()
{
	priority_queue<node> q1,q2;
    int L,n,m;
    scanf("%d%d%d",&L,&n,&m);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(int i=0;i<m;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<n;i++)
    {
        node temp;
        temp.id=i;
        temp.delin=a[i];
        q1.push(temp);
    }   
    for(int i=0;i<m;i++)
    {
        node temp;
        temp.id=i;
        temp.delin=b[i];
        q2.push(temp);
    }
    for(int i=0;i<L;i++)//求出来L件衣服最少洗衣服的时间 
    {
        node temp=q1.top();
        q1.pop(); 
        Atime[i]=temp.delin;
        temp.delin=temp.delin+a[temp.id];
        q1.push(temp);
    }
    ll ans=0;
    for(int i=L-1;i>=0;i--)//从后往前 烘干机时间从小到大 
    {
        node temp=q2.top();
        q2.pop();
        ans=max(ans,Atime[i]+temp.delin);
        temp.delin=temp.delin+b[temp.id];
        q2.push(temp); 
    }
    printf("%lld\n",ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/passer__/article/details/81542676