HDU - 6000 Wash(优先队列+贪心)
2024-10-01 08:17:04
题意:已知有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;
}
最新文章
- centos 7.2 网卡配置文件 及 linux bridge的静态配置
- [UCSD白板题] Huge Fibonacci Number modulo m
- 添加html元素
- windows安装TortoiseGit详细使用教程
- hdu 2042
- BarTender破解问题
- javascript QUnit 单元测试
- Java [leetcode 21]Merge Two Sorted Lists
- LR如何监控tomcat性能
- [Google Codejam] Round 1A 2016 - The Last Word
- (转)java之Spring(IOC)注解装配Bean详解
- MySQL架构备份之M-S-S级联备份
- 缓存:前端页面缓存、服务器缓存(依赖SQL)MVC3
- 执行一个内容为SQL语句的字符串
- springboot2.0添加logback
- CentOS双机中Docker下安装Mysql并配置互为主从模式
- B1010.一元多项式求导
- 2015 年度新增开源软件排名 TOP 100 - 开源中国社区
- 关于bootstrap Modal弹窗 滚动条的问题
- Android-卖票案例static-不推荐此方式