hdu 6180贪心
题意:有m个工程,一台机器在同一时间只能运行一个工程,告诉你每个工程的起始时间和结束时间,求出最少要多少个机器以及最小的机器总运行时间(机器开始了就不能停了,直到用完该台机器才停止)。
题解:由于这里可以使用多台机器,那么我们用起点排序也能够得到最小的k。(对比了下典型的区间调度问题,那个问题由于只有一台机器,所以必须用结束时间排序——尽早结束可以有更多的机会接触更多的时间区间)。然后题目要求最小的工作时间,这里我们只要保证一台机器运行的两个工程之间的时间间隔最小就可以了,也是一个贪心。一开始我用一个队列来维护机器的结束但是这是不行的,因为在判断是否需要新引入一台机器的时候,我们希望队列的首位为结束时间最早的机器;而当我们计算时间的时候,我们希望能有一个符合条件的结束时间最晚的机器来继续现在的工程。所以我们需要两个队列来维护,一个工作队列,一个空闲队列。
ac代码:
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#define N 100010
#define LL __int64
#define inf 0x3f3f3f3f
using namespace std;
const LL mod = 1e9 + ;
struct node {
LL st, en;
}thing[N];
bool cmp1(node a, node b) {
if (a.st == b.st) {
return a.en < b.en;
}
return a.st < b.st;
}
int main() {
cin.sync_with_stdio(false);
int T;
int n;
cin >> T;
while (T--) {
cin >> n;
priority_queue<LL>p;//空闲集合
priority_queue<LL, vector<LL>, greater<LL> >q;//工作集合
for (int i = ; i < n; i++) {
cin >> thing[i].st >> thing[i].en;
}
LL ans = , sum = ;
sort(thing, thing + n, cmp1);
for (int i = ; i < n; i++) {
node now = thing[i];
while ((!q.empty()) && q.top() <= now.st) {
p.push(q.top());
q.pop();
}
if (!p.empty()) {
int num = p.top();
p.pop();
sum += now.en - num;
q.push(now.en);
}
else {
ans++;
sum += now.en - now.st;
q.push(now.en);
}
}
cout << ans << " " << sum << endl;
}
return ;
}
hdu 6180贪心的更多相关文章
- 2017多校第10场 HDU 6180 Schedule 贪心,multiset
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...
- HDU - 6180:Schedule(简单贪心)
There are N schedules, the i-th schedule has start time s i si and end time e i ei (1 <= i < ...
- Schedule HDU - 6180 (multiset , 贪心)
There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). Ther ...
- Hdu 5289-Assignment 贪心,ST表
题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 4803 贪心/思维题
http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么? G++ AC C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...
- hdu 1735(贪心) 统计字数
戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...
- hdu 4974 贪心
http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...
- hdu 4982 贪心构造序列
http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...
- HDU 2307 贪心之活动安排问题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- RK3288 st7703 mipi屏指令过长,程序跑飞
本文为博主原创文章,转载请注明出处:https://www.cnblogs.com/lialong1st/p/11218433.html CPU:RK3288 系统:Android 5.1 调试 mi ...
- Restful API 架构与设计参考原则
1. 什么是RESTREST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. 它首次出现在2000年Roy Fielding的博 ...
- [ERR] 2006 - MySQL server has gone away如何解决
解决方案: max_allowed_packet = 16M 改大点! 文章来源:外星人来地球 欢迎关注,有问题一起学习欢迎留言.评论
- 【分类算法】决策树(Decision Tree)
(注:本篇博文是对<统计学习方法>中决策树一章的归纳总结,下列的一些文字和图例均引自此书~) 决策树(decision tree)属于分类/回归方法.其具有可读性.可解释性.分类速度快等优 ...
- Faster RCNN论文学习
Faster R-CNN在Fast R-CNN的基础上的改进就是不再使用选择性搜索方法来提取框,效率慢,而是使用RPN网络来取代选择性搜索方法,不仅提高了速度,精确度也更高了 Faster R-CNN ...
- spring cloud+.net core搭建微服务架构
http://www.cnblogs.com/longxianghui/p/7800316.html
- webpack概述——资源、样式、图片的打包工具
官方地址:https://www.webpackjs.com/ Concepts At its core, webpack is a static module bundler for modern ...
- Cisco Port-Channel 设置(链路聚合--重点)
Port-Channel 的在实际工作中的主要作用是将两个或多个端口捆绑成为一个虚拟通道. interface Port-channel1 description port(1/0/5-6) swit ...
- C#读取带命名空间的xml
首先带有命名空间的xml读取可以使用Xml.Linq,也可以使用xpath,本文将采用xpath的方式解析. 原文参考了:https://www.cnblogs.com/duanjt/p/544054 ...
- 设置滑动TabBar的显示和隐藏
代码如下: //设置滑动的判定范围 - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint ...