为了能到远方,脚下的每一步都不能少.|

Aurora-JC

园龄:3年1个月粉丝:3关注:4

📂题解
🔖贪心
2022-12-11 14:47阅读: 58评论: 0推荐: 0

#6035. 「雅礼集训 2017 Day4」洗衣服

题目

前言

这个贪心有点妙,考试的时候没有想出来,一看题解恍然大悟。

分析

首先对于洗衣服,显而易见我们可以用堆来处理,可以得出每件衣服洗完的时间 ti,其中 ti 表示的是第 i 早的衣服洗完的时间,那对与烘衣服呢?正着做好像不太好做,因为每件衣服的洗完时间都不同,不能(至少我不会)贪心。那我们可以假定一个洗完烘完衣服的时间,从那个时间点往前做,就是倒着做,然后又可以用堆来做了,得到 si ,含义与 ti 类似,即烘衣服花的时间,那怎么匹配呢,显然是最大的和最小的,次大的和次小的 以此类推。如果不是这样子,显然会使其中一个值变大,使得答案可能会增大,显然不会是最优的。

code

#include<bits/stdc++.h>
#define N 100005
#define M 1000005
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
}
int n,na,nb;
int a[N],b[N];
long long ans,t[M],s[M];
struct node{
long long ed;
int use;
bool operator < (const node &A) const {return A.ed<ed;}
};
priority_queue<node> q1,q2;
signed main(){
// freopen("laundry.in","r",stdin);
// freopen("laundry.out","w",stdout);
n=read(),na=read(),nb=read();
for(int i=1;i<=na;++i) a[i]=read(),q1.push((node){a[i],a[i]});
for(int i=1;i<=nb;++i) b[i]=read(),q2.push((node){b[i],b[i]});
for(int i=1;i<=n;++i){
t[i]=q1.top().ed,q1.push((node){t[i]+q1.top().use,q1.top().use});
q1.pop();
s[i]=q2.top().ed,q2.push((node){s[i]+q2.top().use,q2.top().use});
q2.pop();
}
for(int i=1;i<=n;++i) ans=max(ans,t[i]+s[n-i+1]);
printf("%lld\n",ans);
// fclose(stdin);
// fclose(stdout);
return 0;
}

本文作者:南风未起

本文链接:https://www.cnblogs.com/jiangchen4122/p/16973697.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Aurora-JC  阅读(58)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起