6910: 洗衣服
时间限制: 2 Sec 内存限制: 128 MB
提交: 94 解决: 31
[提交] [状态] [讨论版] [命题人:admin]
题目描述
你现在要洗L件衣服。你有n台洗衣机和m台烘干机。由于你的机器非常的小,因此你每次只能洗涤(烘干)一件衣服。
第i台洗衣机洗一件衣服需要wi分钟,第i台烘干机烘干一件衣服需要di分钟。请问把所有衣服洗干净并烘干,最少需要多少时间?假设衣服在机器间转移不需要时间,并且洗完的衣服可以过一会再烘干。
输入
输入第一行有3个整数L,n和m。第二行有n个整数w1,w2,...,wn。第三行有m个整数d1,d2,...,dm。
输出
输出一行一个整数,表示所需的最少时间。
样例输入
1 1 1
1200
34
样例输出
1234
提示
来源/分类
这是一个很好的思维题
思路:要求所有衣服洗完的最小时间,假设现在我们洗衣服,我们肯定追求在最短的时间内把所有的衣服都洗完,即如果用一台洗衣机洗完一件衣服,下一件衣服我们可以考虑用这台洗衣机继续洗或者我们也可以用其他洗衣机洗,那么如何抉择呢,想一下两台洗衣机,一台时间为t1另一台是t2,如果两件都在t1洗的话 那么花费的时间是t1+t1,如果分开洗那么花费的时间是max(t1,t2),烘干也是同样的道理,上述用优先队列实现,最后我们考虑最小的花费时间,肯定是洗衣服花费时间最多的去对应烘干花费时间最小,然后寻求最大值即可!
美丽的代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define FIN freopen("D://code//in.txt", "r", stdin)
#define ppr(i,x,n) for(int i = x;i <= n;i++)
#define rpp(i,n,x) for(int i = n;i >= x;i--)
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
inline ll qow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline int read() {//读入挂
int ret = 0, c, f = 1;
for(c = getchar(); !(isdigit(c) || c == '-'); c = getchar());
if(c == '-') f = -1, c = getchar();
for(; isdigit(c); c = getchar()) ret = ret * 10 + c - '0';
if(f < 0) ret = -ret;
return ret;
}
ll cost[maxn];//记录洗完i件衣服的最少时间
typedef pair< ll,ll > P;
priority_queue< P,vector< P >,greater< P > >Q1,Q2;
int main()
{
ll l,n,m;
ll ans = 0;
l = read();n = read(); m = read();
ppr(i,1,n){ ll x = read(); Q1.push(make_pair(x,x)); }
ppr(i,1,m){ ll x = read(); Q2.push(make_pair(x,x)); }
ppr(i,1,l)
{
P clothes = Q1.top();
ll x = clothes.first; ll y = clothes.second;
cost[i] = x;
Q1.pop();
Q1.push(make_pair(x+y,y));
}
rpp(i,l,1)
{
P clothes = Q2.top();
ll x = clothes.first;ll y = clothes.second;
ans = max(x+cost[i],ans);
Q2.pop();
Q2.push(make_pair(x+y,y));
}
printf("%lld\n",ans);
return 0;
}