Wash HDU - 6000

xiaoxiao2021-02-28  92

这个题思路就是先最大加最小,先洗出来的找一个甩干最大的,后洗出来的找一个刷干最小的,这样的话理论上是最小的时间

说一下做法,就是两个队列,不断去更新,先去找洗衣服的,然后统计下每一件衣服需要的时间,然后倒着循环从后面去找洗衣最大的,匹配上甩干最小的,还有一个就是需要注意,一个队列,维护的时候,一件衣服洗完,把洗衣机的下一个工作时间也压入

还有一个最重要的事!!!!hdu交g++别交c++不然被坑死迷之超时

#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector> #include <map> #include <queue> #include <math.h> #include <stack> #include <utility> #include <string> #include <sstream> #include <cstdlib> #define LL long long using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 1e6 + 10; int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}}; LL a[maxn]; LL b[maxn]; LL c[maxn]; int L,N,M; struct p { LL cow; LL id; bool operator < (const p&b)const { return cow > b.cow; } }; int main() { int t; int kase = 0; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); priority_queue<p> q1,q2; scanf("%d%d%d",&L,&N,&M); for(int i = 1; i <= N; i++) { scanf("%lld",&a[i]); } for(int i = 1; i <= M; i++) { scanf("%lld",&b[i]); } LL ans = -1; LL time; LL ii; p x,y; for(int i = 1; i <= N; i++) { x.cow = a[i]; x.id = i; q1.push(x); } for(int i = 1; i <= M; i++) { x.cow = b[i]; x.id = i; q2.push(x); } for(int i = 1; i <= L; i++) { y = q1.top(); q1.pop(); ii = y.id; time = y.cow; x.cow = y.cow + a[ii]; x.id = y.id; q1.push(x); c[i] = time; } for(int i = L; i >= 1; i--) { y = q2.top(); q2.pop(); time = y.cow; x.cow = y.cow + b[y.id]; x.id = y.id; q2.push(x); ans = max(ans,time + c[i]); } printf("Case #%d: %lld\n",++kase,ans); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-67481.html

最新回复(0)