2 1 1 1 1200 34 2 3 2 100 10 1 10 10
Case #1: 1234 Case #2: 12
题意:给出L堆衣服,在给n个洗衣机洗一堆衣服要的时间n[i]和m个烘干机烘干一堆衣服要的时间m[i],
衣服洗了可以先放着不烘干,想要得到最快洗完并烘干所有衣服所要的时间。
解题思路:先贪心最快洗完衣服的时间,要使得总时间最小,则最晚洗完的衣服应该用最快的烘干机烘干,所以先把洗衣时间排进优先队列,
洗过衣服的洗衣机再洗一遍可能比没洗过的洗衣机还要快(一个洗衣机多次使用的情况),取出队列队首之后再把队首加上已使用的时间再加入队列,
洗烘干衣服同理,烘干所需的最长时间取决于最后烘干完的衣服,取衣服烘干的过程中取Max就行啦
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned long long ull; 5 #define INF 0x3f3f3f3f 6 const ll MAXN = 1e6 + 7; 7 const ll MOD = 1e9 + 7; 8 const double pi = acos(-1); 9 ll w, d; 10 ll cah1[MAXN], cah2[MAXN]; 11 typedef pair<ll, ll> p; 12 int main() 13 { 14 int t, cnt = 1; 15 scanf("%d", &t); 16 while (t--) 17 { 18 priority_queue<p, vector<p>, greater<p> > q1; 19 priority_queue<p, vector<p>, greater<p> > q2; 20 ll l, n, m; 21 p t; 22 scanf("%lld%lld%lld", &l, &n, &m); 23 for (int i = 0; i < n; i++) 24 { 25 scanf("%lld", &w); 26 q1.push(p(w, w)); 27 //洗衣服的时间 和第几台 28 } 29 for (int i = 0; i < m; i++) 30 { 31 scanf("%lld", &d); 32 q2.push(p(d, d)); 33 } 34 for (int i = 0; i < l; i++) 35 { 36 t = q1.top(); 37 q1.pop(); 38 cah1[i] = t.first; //cah存时间 39 q1.push(p(t.first + t.second, t.second)); //若是时间小继续使用 40 } 41 ll ans = 0; 42 for (int i = l - 1; i >= 0; i--) 43 { 44 t = q2.top(); 45 q2.pop(); 46 ans = max(t.first + cah1[i], ans); 47 q2.push(p(t.first+t.second,t.second)); 48 } 49 printf("Case #%d: %lld\n", cnt++, ans); 50 } 51 return 0; 52 }
原文:https://www.cnblogs.com/graytido/p/10770895.html