HDU - 6180:Schedule(简单贪心)
Print the minimum number K of the machines for performing all schedules, and when only uses K machines, print the minimum sum of all working times.
InputThe first line contains an integer T (1 <= T <= 100), the number of test cases. Each case begins with a line containing one integer N (0 < N <= 100000). Each of the next N lines contains two integers s i si
and e i ei
(0<=s i <e i <=1e9) (0<=si<ei<=1e9)
.OutputFor each test case, print the minimum possible number of machines and the minimum sum of all working times.Sample Input
1
3
1 3
4 6
2 5
Sample Output
2 8
题意:有N个任务,每个任务有自己的起始时间和结束时间,问至少多少个机器可以完成这些任务,使其满足每台机器的任务没有时间交集。
思路:直接贪心,每次找完成时间<=当前任务起始时间的最大的一台机器,如果没有,则弄一台新的机器。
主要是要注意set的二分用s.lower_bound(x),优于lower_bound(s.begin(),s.end(),x);
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
multiset<int>s;
multiset<int>::iterator it;
pair<int,int>a[];
int main()
{
int T,N,K; ll ans;
scanf("%d",&T);
while(T--){
scanf("%d",&N); K=; ans=; s.clear();
rep(i,,N) scanf("%d%d",&a[i].first,&a[i].second);
sort(a+,a+N+);
rep(i,,N){
if(s.empty()||(*s.begin())>a[i].first) {
s.insert(a[i].second); K++; ans-=a[i].first;
}
else{
it=s.upper_bound(a[i].first);
it--;
s.erase(it); s.insert(a[i].second);
}
}
for(it=s.begin();it!=s.end();it++) ans+=(*it);
printf("%d %lld\n",K,ans);
}
return ;
}
HDU - 6180:Schedule(简单贪心)的更多相关文章
- 2017多校第10场 HDU 6180 Schedule 贪心,multiset
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...
- 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 6180 Schedule
Schedule Problem Description There are N schedules, the i-th schedule has start time si and end time ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- CDOJ 1502 string(简单贪心)
题目大意:原题链接 相邻两个字母如果不同,则可以结合为前一个字母,如ac可结合为a.现给定一个字符串,问结合后最短可以剩下多少个字符串 解体思路:简单贪心 一开始读题时,就联想到之前做过的一道题,从后 ...
- ACM_发工资(简单贪心)
发工资咯: Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为广财大的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日 ...
- ACM_Ruin of Titanic(简单贪心)
Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...
随机推荐
- 使用curl 命令模拟POST/GET请求
https://blog.csdn.net/u012340794/article/details/71440604 curl命令是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载 ...
- with as (cte common table expression) 公共表表达式
SQL中 with as 的用法——使用公用表表达式(CTE) 公用表表达式 (CTE) 可以认为是在单个 SELECT.INSERT.UPDATE.DELETE 或 CREATE VIEW 语句的 ...
- Windows:FTP命令大全
Windows:FTP命令大全 简介 1, open:与服务器相连接: 2, send(put):上传文件: 3,get:下载文件: 4,mget:下载多个文件: 用法: mget *:下载当前路径下 ...
- 2018-2019-2 20165114《网络对抗技术》Exp3 免杀原理与实践
Exp3 免杀原理与实践 目录 一.实验内容 二.基础问题回答 (1)杀软是如何检测出恶意代码的? (2)免杀是做什么? (3)免杀的基本方法有哪些? 三.实践过程记录 正确使用msf编码器,msfv ...
- react-native run-android Starting: Intent Error type 3 Error: Activity class does not exist
使用”react-native run-android”命令运行android应用时,如果常常出现如下错误: Starting the app (/home/xxx/soft/sdk//platfor ...
- Delphi_时间间隔
1. var dtOnlineDateTime, dt: TDateTime; begin dt := StrToDateTime('2017/6/28 16:41:30'); dtOnlineDat ...
- scala学习手记11 - 类定义
这里会通过与Java比较的方式来说明scala是如何创建类的. 先来看一下Java中是如何定义一个类的: public class Car { private final int year; priv ...
- VFIO简介
VFIO是一套用户态驱动框架,它提供两种基本服务: 向用户态提供访问硬件设备的接口 向用户态提供配置IOMMU的接口 VFIO由平台无关的接口层与平台相关的实现层组成.接口层将服务抽象为IOCTL命令 ...
- ALS算法 (面试准备)
ALS算法描述: 1.ALS算法用来补全用户评分矩阵.由于用户评分矩阵比较稀疏,将用户评分矩阵进行分解,变成V和U的乘积.通过求得V和U两个小的矩阵来补全用户评分矩阵. 2.ALS算法使用交替最小二乘 ...
- 智课雅思词汇---二十五、-ate
智课雅思词汇---二十五.-ate 一.总结 一句话总结:又是动词,又是名词,又是形容词 后缀:-ate ①[动词后缀] 表示做.造成.使之成....做...事等意义 hyphenate 加连字符 o ...