Wash HDU
来源:互联网 发布:英国现状及地位知乎 编辑:程序博客网 时间:2024/05/18 07:21
这个题思路就是先最大加最小,先洗出来的找一个甩干最大的,后洗出来的找一个刷干最小的,这样的话理论上是最小的时间
说一下做法,就是两个队列,不断去更新,先去找洗衣服的,然后统计下每一件衣服需要的时间,然后倒着循环从后面去找洗衣最大的,匹配上甩干最小的,还有一个就是需要注意,一个队列,维护的时候,一件衣服洗完,把洗衣机的下一个工作时间也压入
还有一个最重要的事!!!!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 longusing 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;}
阅读全文
1 0
- Wash HDU
- hdu 6000 Wash
- hdu 6000 Wash 贪心
- hdu 6000 Wash
- HDu 6000 Wash(贪心)
- 【bzoj5088】HDU 6000 Wash
- HDU-6000-Wash
- Bzoj5088 HDU 6000 Wash
- Hdu 6000 Wash(贪心)
- HDU-6000 Wash 贪心 队列
- hdu 6000 Wash(优先队列)
- bzoj 5088: HDU 6000 Wash
- bzoj 5088: HDU 6000 Wash
- HDU 6000 Wash (优先队列-贪心)
- hdu 6000 Wash(2016 CCPC-Final)
- 【HDU 6000 Wash】优先队列 & 贪心
- bzoj 5088: HDU 6000 Wash 堆+贪心
- HDU 6000 Wash【优先队列优化贪心】【最大值+最小值】
- JAVA 设计模式 访问者模式
- Angular(ng2,ng4)初学及基础知识总结
- JAVA 设计模式 状态模式
- Android 书籍
- 设计模式系列
- Wash HDU
- [Java 基础]字符串
- 在标题栏添加更多选项的功能
- mongodb 与 python3 交互
- [Java 进阶]异常
- [Java 基础]运算符和表达式
- 排序一 冒泡排序
- Gcd(最大公约数)
- 排序二 快速排序