HDU 6000 优先队列+快速IO

来源:互联网 发布:pdf 编辑软件 免费 编辑:程序博客网 时间:2024/05/20 11:19

题意

有L件衣服,N个洗衣机,M个甩干机,每个洗衣机和甩干机都有独立的处理时间,问洗完这些衣服最少需要多少时间。

题解

利用优先队列贪心地去做,也算是模拟吧,把衣服扔到洗衣机中,取出来加到一个数组中(加到队列中会超时)。然后倒着取出来这个数组中的元素(因为我们要保证洗衣机最后洗完的元素优先加到甩干机中,这样才能保证截止时间最短)。最后在所有衣服处理的截止时间中取最大值就可以了。

代码

#include<bits/stdc++.h>#define LL long long#define UP(i,l,h) for(LL i=l;i<h;i++)#define DOWN(i,h,l) for(LL i=h-1;i>=l;i--)#define W(t) while(t)#define INF 0x3f3f3f3f#define MEM(a,b) memset(a,b,sizeof(a))#define BUF 50001000using namespace std;char Buf[BUF],*buf=Buf;struct Node{    LL ed,len;    bool operator < (const Node b) const    {        return ed+len>b.ed+b.len;    }};LL ans;LL big[1001000];int getint(){    char c;    for(; *buf<48; buf++);    int x=0;    W(*buf>47)    {        x=x*10+(*buf-'0');        buf++;    }    return x;}void solve(){//    priority_queue<LL> big;        //大在顶    priority_queue<Node> wash;    priority_queue<Node> dry;    MEM(big,0);    int l,n,m;    l=getint();    n=getint();    m=getint();    UP(i,0,n)    {        Node nd;        nd.len=getint();        nd.ed=0;        wash.push(nd);    }    UP(i,0,m)    {        Node nd;        nd.len=getint();        nd.ed=0;        dry.push(nd);    }    UP(i,0,l)    {        Node tp=wash.top();        wash.pop();        tp.ed+=tp.len;//        big.push(tp.ed);        big[i]=tp.ed;        wash.push(tp);    }    ans=0;    DOWN(i,l,0)    {        LL tp=big[i];        Node nd=dry.top();        dry.pop();        ans=max(ans,tp+nd.ed+nd.len);        nd.ed+=nd.len;        dry.push(nd);    }}int main(){    fread(Buf,1,BUF,stdin);    int t;    t=getint();    int ks=1;    W(t--)    {        solve();        printf("Case #%d: %I64d\n",ks++,ans);    }}
原创粉丝点击