zoukankan      html  css  js  c++  java
  • hdu 6000 Wash

    题意:L件衣服,N个洗衣机,M个烘干机,给出每个洗衣机洗一件衣服的时间和烘干机烘干一件衣服的时间,问需要的最少时间是多少

    思路:贪心+优先队列,光想着暴力找出前L个时间了。。用优先队列可以快速找到每一件衣服出来的时间,然后我们可以同样知道在前L个时刻甩干机是工作的,那肯定是倒着来

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int N=1e6+10;
     5 
     6 int L,n,m;
     7 ll c[N];
     8 struct node{
     9     ll v,base;
    10     node(ll x,ll y){
    11         v=x;base=y;
    12     }
    13     bool operator<(const node &a) const {
    14         return v>a.v;
    15     }
    16 };
    17 priority_queue<node>q1,q2;
    18 int main(){
    19     int t;
    20     int k=1;
    21     cin>>t;
    22     while(t--){
    23         while(!q1.empty()) q1.pop();
    24         while(!q2.empty()) q2.pop();
    25         scanf("%d%d%d",&L,&n,&m);
    26         for(int i=1;i<=n;i++){
    27             ll x;
    28             scanf("%lld",&x);
    29             q1.push(node(x,x));
    30         }
    31         for(int i=1;i<=m;i++){
    32             ll x;
    33             scanf("%lld",&x);
    34             q2.push(node(x,x));
    35         }
    36         for(int i=0;i<L;i++){
    37             node x=q1.top();q1.pop();
    38             c[i]=x.v;
    39             x.v+=x.base;
    40             q1.push(x);
    41         }
    42         ll sum=0;
    43         for(int i=L-1;i>=0;i--){
    44             node x=q2.top();q2.pop();
    45             sum=max(sum,x.v+c[i]);
    46             x.v+=x.base;
    47             q2.push(x);
    48         }
    49         printf("Case #%d: %lld
    ",k++,sum);
    50     }
    51 }
  • 相关阅读:
    25-javaweb接入支付宝支付接口
    4-js 函数
    24-filter-拦截器
    23-新建maven 项目
    22-maven-安装与配置
    15-matlab矩阵运用
    2018.7.18 div,section,article的区别和使用
    2018.7.17 牛客网训练
    2018.7.16常用推荐算法
    2018.7.15 解决css中input输入框点击时去掉外边框方法
  • 原文地址:https://www.cnblogs.com/hhxj/p/7525875.html
Copyright © 2011-2022 走看看