HDU - 6000 Wash(优先队列+贪心)
Posted SomnusMistletoe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 6000 Wash(优先队列+贪心)相关的知识,希望对你有一定的参考价值。
题意:已知有L件衣服,M个洗衣机,N个烘干机,已知每个机器的工作时间,且每个机器只能同时处理一件衣服,问洗烘完所有衣服所需的最短时间。
分析:
1、优先队列处理出每件衣服最早的洗完时间。
2、优先队列处理出每件衣服最早的烘完时间。
3、用最大的洗完时间与最小的烘完时间相加,取最大值。
#include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include<cmath> #include<iostream> #include<sstream> #include<iterator> #include<algorithm> #include<string> #include<vector> #include<set> #include<map> #include<stack> #include<deque> #include<queue> #include<list> #define Min(a, b) ((a < b) ? a : b) #define Max(a, b) ((a < b) ? b : a) const double eps = 1e-8; inline int dcmp(double a, double b){ if(fabs(a - b) < eps) return 0; return a > b ? 1 : -1; } typedef long long LL; typedef unsigned long long ULL; const int INT_INF = 0x3f3f3f3f; const int INT_M_INF = 0x7f7f7f7f; const LL LL_INF = 0x3f3f3f3f3f3f3f3f; const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f; const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1}; const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1}; const int MOD = 1e9 + 7; const double pi = acos(-1.0); const int MAXN = 1000000 + 10; const int MAXT = 10000 + 10; using namespace std; struct Node{ LL len, et; Node(LL l, LL t):len(l), et(t){} bool operator < (const Node& rhs)const{ return et > rhs.et; } }; LL washet[MAXN]; priority_queue<Node> q; int main(){ int T; scanf("%d", &T); int kase = 0; while(T--){ while(!q.empty()) q.pop(); int L, N, M; scanf("%d%d%d", &L, &N, &M); LL x; for(int i = 0; i < N; ++i){ scanf("%lld", &x); q.push(Node(x, x)); } for(int i = 0; i < L; ++i){ Node top = q.top(); q.pop(); washet[i] = top.et; q.push(Node(top.len, top.et + top.len)); } while(!q.empty()) q.pop(); for(int i = 0; i < M; ++i){ scanf("%lld", &x); q.push(Node(x, x)); } LL ans = 0; for(int i = L - 1; i >= 0; --i){ Node top = q.top(); q.pop(); ans = max(ans, washet[i] + top.et); q.push(Node(top.len, top.et + top.len)); } printf("Case #%d: %lld\n", ++kase, ans); } return 0; }
以上是关于HDU - 6000 Wash(优先队列+贪心)的主要内容,如果未能解决你的问题,请参考以下文章
hdu6000 Wash ccpc-20162017-finals B Wash