zoukankan      html  css  js  c++  java
  • HDU 6000 Wash【优先队列优化贪心】【最大值+最小值】

    Wash

    Time Limit: 20000/10000 MS (Java/Others)

    Memory Limit: 64000/64000 K (Java/Others)

    Description

    Mr.Panda is about to engage in his favourite activity doing laundry! He’s brought L indistinguishable loads of laundry to his local laundromat, which has N washing machines and M dryers.The ith washing machine takes Wi minutes to wash one load of laundry, and the ith dryer takes Di minutes to dry a load of laundry.
    At any point in time, each machine may only be processing at most one load of laundry.
    As one might expect, Panda wants to wash and then dry each of his L loads of laundry. Each load of laundry will go through the following steps in order:
    1. A non-negative amount of time after Panda arrives at the laundromat, Panda places the load in an unoccupied washing machine i.
    2. Wi minutes later, he removes the load from the washing machine, placing it in a temporary holding basket (which has unlimited space)
    3. A non-negative amount of time later, he places the load in an unoccupied dryer j
    4. Dj minutes later, he removes the load from the dryer Panda can instantaneously add laundry to or remove laundry from a machine. Help Panda minimize the amount of time (in minutes after he arrives at the laundromat) after which he can be done washing and drying all L loads of laundry!

    Input

    The first line of the input gives the number of test cases, T.
    T test cases follow. Each test case consists of three lines. The first line contains three integer L, N, and M.
    The second line contains N integers W1,W2,...,WN representing the wash time of each wash machine.
    The third line contains M integers D1,D2,...,DM representing the dry time of each dryer.

    Output

    For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the minimum time it will take Panda to finish his laundry.

    limits


    1T100.
    1L106.
    1N,M105.
    1Wi,Di109.

    Sample Input

    2 1 1 1 1200 34 2 3 2 100 10 1 10 10

    Sample Output

    Case #1: 1234 Case #2: 12

    Hint

    jiangzijing2015

    洗衣的最小值加甩干的最大值

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define ms(x,y) memset(x,y,sizeof(x))
    using namespace std;
    
    typedef long long ll;
    
    const double pi = acos(-1.0);
    const int mod = 1e9 + 7;
    const int maxn = 1e5 + 5;
    
    ll w[100005],d[100005],a[1000005],b[1000005],l,m,n;
    
    struct Node
    {
    	ll cost,next;
    	Node(ll a,ll b)
    	{
    		cost = a;
    		next = b;
    	}
    	Node(){}
    	friend bool operator < (Node a, Node b)
    	{
    		return a.next > b.next;
    	}
    };
    
    ll solve()
    {
    	ll ans = 0;
    	priority_queue<Node> qa, qb;
    	for(int i=0;i<n;i++)
    	{
    		qa.push(Node(w[i],w[i]));
    	}
    	for(int i=0;i<m;i++)
    	{
    		qb.push(Node(d[i],d[i]));
    	}
    	for(int i=0;i<l;i++)
    	{
    		Node tmp = qa.top();qa.pop();
    		a[i] = tmp.next;
    		//printf("a[%d] = %lld
    ",i, a[i]);
    		tmp.next += tmp.cost;
    		qa.push(tmp);
    	}
    	for(int i=l-1;i>=0;i--)
    	{
    		Node tmp = qb.top();qb.pop();
    		b[i] = tmp.next;
    
    		//printf("b[%d] = %lld
    ",i, b[i]);
    		tmp.next += tmp.cost;
    		qb.push(tmp);
    		ans = max(ans, b[i] + a[i]);
    	}
    	return ans;
    }
    
    int main()
    {
    	//freopen("in.txt","r",stdin);
    	//freopen("out.txt","w",stdout);
    	int t;
    	scanf("%d",&t);
    	for(int cas = 1;cas <= t; cas++)
    	{
    		scanf("%lld%lld%lld",&l,&n,&m);
    		for(int i=0;i<n;i++)
    			scanf("%lld",&w[i]);
    		for(int i=0;i<m;i++)
    			scanf("%lld",&d[i]);
    		ll ans = solve();
    		printf("Case #%d: %lld
    ", cas, ans);
    	}
    	return 0;
    }
    Fighting~
  • 相关阅读:
    TP6框架中如何无刷新上传文件
    TP6框架设置验证码的宽度和高度后,验证码显示不全
    TP6模板缓存问题
    TP6管理后台实战第五天文章管理
    20211027技术人为什么建议写博客
    TP6管理后台实战第六天系统管理
    博客园自定义菜单
    xcat无法连接服务器
    lsf安装后配置
    xcat网络无盘启动——添加自定义安装包
  • 原文地址:https://www.cnblogs.com/Archger/p/8451558.html
Copyright © 2011-2022 走看看