There are N schedules, the i-th schedule has start time s i  si and end time e i  ei (1 <= i <= N). There are some machines. Each two overlapping schedules cannot be performed in the same machine. For each machine the working time is defined as the difference between time end  timeend and time start  timestart , where time_{end} is time to turn off the machine and time start  timestart is time to turn on the machine. We assume that the machine cannot be turned off between the time start  timestart and the time end  timeend .
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(简单贪心)的更多相关文章

  1. 2017多校第10场 HDU 6180 Schedule 贪心,multiset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...

  2. Schedule HDU - 6180 (multiset , 贪心)

    There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). Ther ...

  3. hdu 6180 Schedule

    Schedule Problem Description There are N schedules, the i-th schedule has start time si and end time ...

  4. CF 628C --- Bear and String Distance --- 简单贪心

    CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...

  5. HDU 2085 核反应堆 --- 简单递推

    HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...

  6. HDU 4442 Physical Examination(贪心)

    HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...

  7. Uva 11729 Commando War (简单贪心)

    Uva 11729  Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...

  8. CDOJ 1502 string(简单贪心)

    题目大意:原题链接 相邻两个字母如果不同,则可以结合为前一个字母,如ac可结合为a.现给定一个字符串,问结合后最短可以剩下多少个字符串 解体思路:简单贪心 一开始读题时,就联想到之前做过的一道题,从后 ...

  9. ACM_发工资(简单贪心)

    发工资咯: Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为广财大的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日 ...

  10. ACM_Ruin of Titanic(简单贪心)

    Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...

随机推荐

  1. iOS 多线程安全 与 可变字典

    这周最大的收获是稍稍通透了 多线程安全字典的重要性.  诱因是,发现了有字典坏地址错误      果断以为是 value 或者 key 是可能出现了空值,补充了潜在的判断,虽然有的位置已经预判断的,但 ...

  2. 利用ntp自动同步时间

    实验环境:centos 6.10 1.安装ntp工具 yum install -y ntp 2.便宜/etc/ntp.conf文件,添加远程时间服务器 server ntp1.aliyun.com s ...

  3. List To Json

    命名空间 using Newtonsoft.Json; 实例代码 /// <summary> /// 将list集合转换为json /// </summary> /// < ...

  4. Python3.x:Linux下退出python命令行

    Python3.x:Linux下退出python命令行 退出命令: quit() #或者 exit() #或者 Ctrl-D

  5. gvim中对变量的识别

    最近在项目中使用gvim打开一个文件,发现对某个变量不识别. 后来发现是gvim中对{$comm_ver},带花括号的变量不识别. 类似这样:parameter memory_spec = " ...

  6. 一键配置IP地址脚本

    #/bin/bash NETPWD='/etc/sysconfig/network-scripts/' read -p "please enten net num(1,2,3,4) : &q ...

  7. C\C++与Java中的static关键字

    C\C++里面的static: 面向过程的static: 在c和c++面向过程的设计里,在全局变量前加上static关键字则可将该变量定义为一个静态全局变量,比如: static int a; 那么c ...

  8. Centos6.5 安装gitlab 并使用自带的nginx

    Centos6.5 安装gitlab 并使用自带的nginx 1.安装依赖 yum -y install policycoreutils openssh-server openssh-clients ...

  9. Maven添加Oracle驱动及依赖

    oracle驱动先去官网下载,下载下来后,需要安装到maven本地仓库,然后再pom中添加依赖. 1下载oracle驱动包 ojdbc6-11.2.0.3.jar 2命令行安装到maven仓库 mvn ...

  10. const对象 不能调用非const修饰的成员函数

    class class UIRect:public RECT { public: UIRect(LONG leftT = 0, LONG topT = 0, LONG rightT = 0, LONG ...