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. 使用 libevent 和 libev 提高网络应用性能(IBM)

    http://www.ibm.com/developerworks/cn/aix/library/au-libev/

  2. netty2---服务端和客户端

    客户端: package com.client; import java.net.InetSocketAddress; import java.util.Scanner; import java.ut ...

  3. jQuery垂直滑动切换焦点图

    在线演示 本地下载

  4. 字符串的hash匹配

    如果要比较字符串是否相等,首先想到的是KMP算法,但是hash更加简洁易于编写,hash的目的是把一串字符转化成一个数字,用数字来比较是否相等.我让mod=912837417 Base=127,防止h ...

  5. codeforces 738

    D: 题意:一行1*n的格子放船只,船数为a,船的长度为b,每格为0或1,1表示该格并不是船只的一部分,找出最少的格子数使得射击这些格子至少能打中一艘船. 思路:船的长度为b,即每段连续的长度为b的0 ...

  6. dubbo用户指南-总结

    dubbo用户指南-总结 入门 背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用 ...

  7. 八步学会数据迁移:ETL工具kettle使用方法

    一.目的 将不同服务器上的表合并到另外一个服务器上.例如:将服务器1上的表A和服务器2上的表B,合并到服务器3上的表C 要求:表A需要被裁剪(去掉不必要的字段).表B需要增加一些字段 二.使用方法 ( ...

  8. 大家来聊聊如何PASS 360

    真正做到PASS 360,启动项什么的.我觉得还是有可能的把? 虽然它就是一个流氓,但是我们要想办法比它更流氓. 只是有一个点:那就是行为监控,那既然行为监控(云分析抛开).那就找一个可信任的程序来调 ...

  9. JavaWeb -- Struts2 ResultType细化, 国际化

    1. ResultType细化 <result-types> <result-type name="chain" class="com.opensymp ...

  10. Search in Rotated Sorted Array, 查找反转有序序列。利用二分查找的思想。反转序列。

    问题描述:一个有序序列经过反转,得到一个新的序列,查找新序列的某个元素.12345->45123. 算法思想:利用二分查找的思想,都是把要找的目标元素限制在一个小范围的有序序列中.这个题和二分查 ...