HDU 6000 优先队列+快速IO
来源:互联网 发布:pdf 编辑软件 免费 编辑:程序博客网 时间:2024/05/20 11:19
题意
有L件衣服,N个洗衣机,M个甩干机,每个洗衣机和甩干机都有独立的处理时间,问洗完这些衣服最少需要多少时间。
题解
利用优先队列贪心地去做,也算是模拟吧,把衣服扔到洗衣机中,取出来加到一个数组中(加到队列中会超时)。然后倒着取出来这个数组中的元素(因为我们要保证洗衣机最后洗完的元素优先加到甩干机中,这样才能保证截止时间最短)。最后在所有衣服处理的截止时间中取最大值就可以了。
代码
#include<bits/stdc++.h>#define LL long long#define UP(i,l,h) for(LL i=l;i<h;i++)#define DOWN(i,h,l) for(LL i=h-1;i>=l;i--)#define W(t) while(t)#define INF 0x3f3f3f3f#define MEM(a,b) memset(a,b,sizeof(a))#define BUF 50001000using namespace std;char Buf[BUF],*buf=Buf;struct Node{ LL ed,len; bool operator < (const Node b) const { return ed+len>b.ed+b.len; }};LL ans;LL big[1001000];int getint(){ char c; for(; *buf<48; buf++); int x=0; W(*buf>47) { x=x*10+(*buf-'0'); buf++; } return x;}void solve(){// priority_queue<LL> big; //大在顶 priority_queue<Node> wash; priority_queue<Node> dry; MEM(big,0); int l,n,m; l=getint(); n=getint(); m=getint(); UP(i,0,n) { Node nd; nd.len=getint(); nd.ed=0; wash.push(nd); } UP(i,0,m) { Node nd; nd.len=getint(); nd.ed=0; dry.push(nd); } UP(i,0,l) { Node tp=wash.top(); wash.pop(); tp.ed+=tp.len;// big.push(tp.ed); big[i]=tp.ed; wash.push(tp); } ans=0; DOWN(i,l,0) { LL tp=big[i]; Node nd=dry.top(); dry.pop(); ans=max(ans,tp+nd.ed+nd.len); nd.ed+=nd.len; dry.push(nd); }}int main(){ fread(Buf,1,BUF,stdin); int t; t=getint(); int ks=1; W(t--) { solve(); printf("Case #%d: %I64d\n",ks++,ans); }}
阅读全文
0 0
- HDU 6000 优先队列+快速IO
- hdu 6000 Wash(优先队列)
- HDU 6000 Wash (优先队列-贪心)
- 【HDU 6000 Wash】优先队列 & 贪心
- HDU-1509 优先队列
- hdu 4006 优先队列
- hdu 2757 优先队列
- HDU 4006 优先队列
- hdu 1509 优先队列
- HDU 4006优先队列
- hdu 1873优先队列
- 【优先队列】HDU Rescue
- HDU 4546 优先队列
- hdu 5437 (优先队列)
- hdu-5596 优先队列
- hdu 4544 优先队列
- HDU 4302 优先队列
- HDU 5360 优先队列
- C# 动态调用com
- java项目生成可执行文件(exe)
- 【PostgreSQL-9.6.3】LOG: unrecognized configuration parameter "dynamic_shared_memory_type"
- 图解LSTM神经网络架构及其11种变体(附论文)
- 测试maven镜像是否可用
- HDU 6000 优先队列+快速IO
- 将wordpress admin bar中用户登出后跳转至登陆页面修改为登出前页面
- 1018:尼科彻斯定理
- scikit-learn Tutorials-KNN
- 【poj 2785】4 Values whose Sum is 0 【折半枚举】
- ajax常用参数
- visualDSP++3.5 安装
- 循环队列Queue--使用顺序存储结构(数组)实现
- hdu4463 Outlets