贪心思路,最先洗完的衣服扔给所需甩干时间最长的甩干机,好像是叫最大加最小的思想吧,也算是一道思维题了,在我看来麻烦的是如何求第 i 件衣服所需的最短洗涤时间和最长甩干时间,优先队列真好用啊,还有还有,一份简洁的代码可真好看
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
struct mac
{
ll t,base;
mac(ll a,ll b):t(a),base(b){}
bool operator <(const mac &p)const
{
return t > p.t;
}
};
ll c[maxn];
priority_queue<mac> q1,q2;
int main()
{
int T;
scanf("%d",&T);
for(int k = 1;k <= T;k++)
{
int l,n,m;
ll sum = 0;
memset(c,0,sizeof(c));
while(!q1.empty()) q1.pop();
while(!q2.empty()) q2.pop();
scanf("%d%d%d",&l,&n,&m);
for(int i = 1;i <= n;i++)
{
ll x; scanf("%I64d",&x);
q1.push(mac(x,x));
}
for(int i = 1;i <= m;i++)
{
ll x; scanf("%I64d",&x);
q2.push(mac(x,x));
}
for(int i = 1;i <= l;i++)
{
mac now = q1.top(); q1.pop();
c[i] = now.t;//
now.t += now.base;//
q1.push(mac(now));
}
for(int i = l;i >= 1;i--)
{
mac now = q2.top(); q2.pop();
//printf("%I64d %I64d\n",sum,c[i] + now.t);
sum = max(sum,c[i] + now.t);//
now.t += now.base;//
q2.push(mac(now));
}
printf("Case #%d: %I64d\n",k,sum);
}
}