hdu 6180 Schedule
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.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
int st;//记录入点和出点
int flag;//如果是入点就+1,否则就-1
}s[*+]; int L[+],R[+];//记录机器的开始时间 和 结束时间 bool cmp(node a,node b)
{
if(a.st != b.st)
return a.st<b.st;//就是按照端点排序
else
return a.flag < b.flag;//因为区间结束的时候 和另一个区间开始的会重叠
//so 让区间先结束 然后在开始 这样子的吧
} void init()
{
memset(L,,sizeof(L));
memset(R,,sizeof(R));
}
int main ()
{
int t;
scanf("%d",&t);
while (t--)
{
init();
int n;
scanf("%d",&n);
int m=;
for(int i=;i<n;i++)
{
int st,e;
scanf("%d %d",&st,&e);
s[m].st = st,s[m++].flag=;//左端点+1
s[m].st = e,s[m++].flag=-;//右端点-1
}
sort(s,s+m,cmp);
int sum=,ans=;
for(int i=;i<m;i++)
{
sum+=s[i].flag;
if(sum>ans)
{
ans = sum;
L[sum] = s[i].st;
}
}
sum=,ans=;
for(int i=m-;i>=;i--)
{
sum-=s[i].flag;
if(sum>ans)
{
ans = sum;
R[sum] = s[i].st;
}
}
ll res=;
for(int i=;i<=ans;i++)
{
res += (R[i]-L[i]);
}//因为最后就是R-L 所以这里不用管 R[i]和L[i]是否对应
cout<<ans<<" "<<res<<endl;
}
}
#include<bits/stdc++.h>
using namespace std;
struct node{
int l,r;
bool operator <(const node a)const{
return l<a.l;
}
}seg[];
multiset<int>s;
multiset<int>::iterator it;
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
s.clear();
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d %d",&seg[i].l,&seg[i].r);
}
int ans = ;//记录所用机器数量
long long res = ;//记录时间
sort(seg,seg+n);
for(int i=;i<n;i++)
{
it = s.upper_bound(seg[i].l);//寻找 >= seg[i].l 的r
if(it == s.begin())
{
ans++; //找不到 就重新开一个机器
res += seg[i].r - seg[i].l;
s.insert(seg[i].r);
continue;
}
it--;//这里就是离该i区间的起始点最近的 结束点
res += seg[i].r - *it;//把该i区间的结束点 接上上个结束点 这样就不用管 起始点在哪里了
s.erase(it);//把当前区间结束点删除
s.insert(seg[i].r);//重新更新
}
cout<<ans<<" "<<res<<endl;
}
}
hdu 6180 Schedule的更多相关文章
- 2017多校第10场 HDU 6180 Schedule 贪心,multiset
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...
- HDU - 6180:Schedule(简单贪心)
There are N schedules, the i-th schedule has start time s i si and end time e i ei (1 <= i < ...
- 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 1534 Schedule Problem (差分约束)
Schedule Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 6180贪心
题意:有m个工程,一台机器在同一时间只能运行一个工程,告诉你每个工程的起始时间和结束时间,求出最少要多少个机器以及最小的机器总运行时间(机器开始了就不能停了,直到用完该台机器才停止). 题解:由于这里 ...
- HDU 3572 Task Schedule(拆点+最大流dinic)
Task Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 3572 Task Schedule 网络流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3572 Our geometry princess XMM has stoped her study i ...
- hdu 1150 Machine Schedule 最少点覆盖
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
随机推荐
- tomcatserver解析(五)-- Poller
在前面的分析中介绍过,Acceptor的作用是控制与tomcat建立连接的数量,但Acceptor仅仅负责建立连接.socket内容的读写是通过Poller来实现的. Poller使用java n ...
- BUG笔记:Win8 IE10下input[type="password"]内字符显示被截取问题
这个BUG发生的截图: 这是发生在Windows8 IE10下,type为password的input文本框内输入长串字符后,初次失去焦点的时候会发生的一个BUG. 发生BUG的原因是这个文本框上应用 ...
- 005-四种常见的 POST 提交数据方式
1.http请求方法 HTTP Method RFC Request Has Body Response Has Body Safe Idempotent Cacheable GET RFC 7231 ...
- 既生list何生tuple
python中list是可以修改的;若要创建一系列不可修改的元素时,就需要tuple. 用 tuple 的好处: 1.tuple 比 list 操作速度快.如果您定义了一个值的常量集,并且唯一要用它做 ...
- Apache 配置多个HTTPS站点
作中经常会遇到多个站点实现https访问,并指向同一个网页,本文将详解如何在Centos 环境下配置Apache多站点实现HTTPS访问. 准备工作 OS:CentOS release 6.8 (Fi ...
- POJ3087:Shuffle'm Up(模拟)
http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...
- liferay中如何获取实例的id和portletId
在Portlet中request分为两种renderRequet和actionRequest而portlet需要取得实例Id的时候都在renderRequest的时候才可以取到,如下例子 Portle ...
- STA分析(三) cmos模型
CMOS集成电路的基本结构是以P型材料作为衬底(p-substrate),直接生成NMOS, 同时增加N肼(n-well),在其上制造PMOS. 增加两个bulk(P+,N+)防止非MOS管内的PN结 ...
- suiyi
<?php namespace app\controllers; use Yii;use app\models\Device;use app\models\DeviceSearch;use ap ...
- cf249D
这题说的是给了一个n*m的网格,然后每个格子的点事黑色的或者是白色的然后每个点如图所示 然后只能用白点和图中给出的边建立三角形然后询问三角形的个数有多少个,这样说每个三角形的边必须是图中有的边, ...