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. redis 笔记02 对象、数据库

    对象 Redis并没有使用之前介绍的数据结构来实现键值对数据库,而是基于那些数据结构创建了一个对象系统,这个系统包含字符串对象.列表对象.哈希对象.集合对象和有序集合对象这五种类型对象, 每种对象都用 ...

  2. Linux 上下左右键变成^A,^B,^C,^D解决方法

    用gedit打开 /etc/vim/vimrc.tiny,将里面的 set compatible 改成 set nocompatible 对于退格键backspace的问题,只需在刚才那句话下面加上一 ...

  3. 利用SSH协议在Windows下使用PuTTY连接Ubuntu

    利用SSH协议在Windows下使用PuTTY连接Ubuntu Ubuntu部分 首先我们要为Ubuntu配置一下环境,让它支持ssh服务,我们要做的其实也很简单,就一下两步: 安装OpenSSH软件 ...

  4. J2EE--Hibernate基础笔记

    因为写的是基础内容,所以在这里,(映射集合.映射组件.复合主键和联合主键,jpa annotation,关联映射,hql等等实用内容)都不会提到- 这里写的就是试用李刚<J2EE实战>那本 ...

  5. Navicat Premium 10/12——破解激活

    Navicat Premium 12官方Windows64位百度云 链接:https://pan.baidu.com/s/1hGmDljszQsUoi194CYdfmA 密码:1xff 官方下载链接 ...

  6. Git和GitHub相关

    组员从GitHub上下载项目并上传项目的步骤如下 .组员接收到组长发的项目地址,组员需要从GitHub上把项目克隆下来,首先组员 需要在本地的一个文件夹里打开git,然后运行如下代码:git clon ...

  7. tyvj 1059 过河 dp

    P1059 过河 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 NOIP2005 提高组 第二道 描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳 ...

  8. Java条件语句之 if

    生活中,我们经常需要先做判断,然后才决定是否要做某件事情.例如,如果考试成绩大于 90 分,则奖励一个 IPHONE 5S .对于这种“需要先判断条件,条件满足后才执行的情况”,就可以使用if 条件语 ...

  9. 前端分布引导插件IntroJs的使用

    在用户第一次使用网站的时候,一般会提供新手引导的提示,提示用户重要的功能使用,实现方法比较多,但是有一点,屏幕的自适应问题,大多数自己写的实现方法无非就是一个div遮罩层,然后再需要指引的位置放置一张 ...

  10. Maven到底是个啥玩意

    Maven,是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. 上面是百度百科对Maven的正式介绍,如果你是Maven初学者,我估计你看完之后心中肯 ...