hdu 6000 Wash(2016 CCPC-Final)

题目分析

这道题一开始拿到真的是不怎么会做,看了别人的贪心解法后来自己才知道怎么做。对于洗衣服的过程我们有L件衣服,我们可以用优先队列每次算出最先洗完衣服的时间,这个处理想必大家都会,当然我也想到了,但是后来的事情没有想到,我并不知道关于烘干衣服如何处理,感觉衣服洗完的时间不一样,烘干不知道怎么处理才是最优解,然后自己就傻了,其实烘干衣服可以跟洗衣服一样的方式处理,我们同样利用优先队列处理出L件衣服的烘干时间,然后把烘干的最小时间与洗衣服的最大时间,烘干的最大时间与洗衣服的最小时间相对应,这样可以保证最大的时间最小。然后输出就可。

#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
const int maxn = 1e6+100;

struct Node{
    LL a, val;
    Node(){}
    Node(LL _a, LL _val):a(_a), val(_val){ }
    bool operator < (const Node& temp)const{
        return val > temp.val;
    }
};

priority_queue <Node> pq;
LL t[maxn];

int main(){
    int T, L, M, N;
    scanf("%d", &T);
    for(int kase = 1; kase <= T; kase++){
      //  while(!pq.empty()) pq.pop();
        scanf("%d%d%d", &L, &M, &N);
        LL x;
        for(int i = 0; i < M; i++){
            scanf("%I64d", &x);
            pq.push(Node(x, x));
        }
        for(int i = 0; i < L; i++){
            Node temp = pq.top(); pq.pop();
            t[i] = temp.val;
            pq.push(Node(temp.a, temp.val + temp.a));
        }
        while(!pq.empty()) pq.pop();
        LL ans = 0;
        for(int i = 0; i < N; i++){
            scanf("%I64d", &x);
            pq.push(Node(x, x));
        }
        for(int i = L-1; i >= 0; i--){
            Node temp = pq.top(); pq.pop();
            ans = max(ans, t[i]+temp.val);
            pq.push(Node(temp.a, temp.val + temp.a));
        }
        printf("Case #%d: %I64d\n", kase, ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值