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做了一个梦.梦见当泰坦尼 ...
随机推荐
- 筛选最新生成的报告——sort
筛选出最新报告发送,返回报告路径 import os def filePath(path): return os.path.join(os.path.abspath(os.path.dirname(o ...
- iOS 多线程安全 与可变数组
完全来自于iOS 多线程安全与可变字典 的学习 基本相同,举一反三 直接上样例代码 是我参照网上,根据当前业务需求改的. 其实好多人在这里喜欢用类别处理.我个人觉得用类别 极其容易和普通方法混淆,所以 ...
- javascript Date对象 之 获取时间
javascript Date对象 --> 获取时间: 测试代码: <!DOCTYPE html> <html lang="en"> <head ...
- return false 和 return true
常规用法 在普通函数中:return 语句终止函数的执行,并返回一个指定的值给函数调用者,一般会用一个变量接收这个返回值再进行其它处理.如果未指定返回值,则返回 undefined 其中,返回一个函数 ...
- hadoop08---读写锁
ReentrantLock 直接使用lock接口的话,我们需要实现很多方法,不太方便,ReentrantLock是唯一实现了Lock接口的类,并且ReentrantLock提供了更多的方法,Reen ...
- Mybatis中trim的使用
trim标记是一个格式化的标记,可以完成set或者是where标记的功能,如下代码: 1. select * from user <trim prefix="WHERE" p ...
- python中多重继承与获取对象
1.python中多重继承 除了从一个父类继承外,Python允许从多个父类继承,称为多重继承. 多重继承的继承链就不是一棵树了,它像这样: class A(object): def __init__ ...
- Word Search, 在矩阵中寻找字符串,回溯算法
问题描述: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed ...
- app下载——js设备判断
摘自:今日头条<!doctype html> <html lang="en"> <head> <meta charset="UT ...
- python fire库的使用
一. 介绍 fire是python中用于生成命令行界面(Command Line Interfaces, CLIs)的工具,不需要做任何额外的工作,只需要从主模块中调用fire.Fire(),它会自动 ...