#1309 : 任务分配
时间限制:10000ms
单点时限:1000ms
内存限制:256MB
-
5 1 10 2 7 6 9 3 4 7 10
样例输出 -
3
描述
给定 N 项任务的起至时间( S1, E1 ), ( S2, E2 ), ..., ( SN, EN ), 计算最少需要多少台机器才能按时完成所有任务。
同一时间一台机器上最多进行一项任务,并且一项任务必须从头到尾保持在一台机器上进行。任务切换不需要时间。
输入
第一行一个整数 N,(1 ≤ N ≤ 100000),表示任务的数目。 以下 N 行每行两个整数 Si, Ei,(0 ≤ Si < Ei ≤ 1000000000),表示任务的起至时间。
输出
输出一个整数,表示最少的机器数目。
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
struct times
{
ll x,y;
bool operator <(const times&T) const
{
return T.y<y;
}
}t[100010];
bool cmp(const times &a,const times &b)
{
return (a.x==b.x?a.y<b.y:a.x<b.x);
}
int main()
{
int n;
scanf("%d",&n);
int i;
for(i=0;i<n;i++)
scanf("%lld%lld",&t[i].x,&t[i].y);
sort(t,t+n,cmp);
priority_queue<times> q;
q.push(t[0]);
ll ans=1;
for(i=1;i<n;i++)
{
if(t[i].x<q.top().y)
ans++;
else
q.pop();
q.push(t[i]);
}
printf("%d\n",ans);
}