题意:给你n个任务的开始时间和结束时间,一个机器同时最多执行一个任务,问你最少要几个机器。保证机器最少的前提下,问你每个机器的开动时间(最后一次关闭-第一次开启)之和最少是多少。

把这些线段画在数轴上,最大的重叠数就是最少要几个机器。

开动时间怎么算呢?第i个机器的开动时间其实就是(再也不需要>=i台机器的第一个位置 - 需要>=i台机器的第一个位置)。对每个机器的这个值求和即可。

要先离散化。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Point{
int p,v;
}t[200005];
bool cmp(const Point &a,const Point &b)
{
return a.v<b.v;
}
int T,n;
int xs[100005],ys[100005],a[200005],ma[200005],Left[200005],Right[200005];
int sufmax[200005];
int main(){
//freopen("1010.in","r",stdin);
scanf("%d",&T);
for(;T;--T){
memset(a,0,sizeof(a));
memset(ma,0,sizeof(ma));
memset(Left,0x7f,sizeof(Left));
memset(Right,0,sizeof(Right));
memset(sufmax,0,sizeof(sufmax));
int all=0;
scanf("%d",&n);
for(int i=1;i<=n;++i){
++all;
scanf("%d",&t[all].v);
t[all].p=all;
++all;
scanf("%d",&t[all].v);
t[all].p=all;
}
sort(t+1,t+all+1,cmp);
int zy=0;
if(t[1].p%2==1){
xs[(t[1].p+1)/2]=++zy;
}
else{
ys[t[1].p/2]=++zy;
}
ma[zy]=t[1].v;
for(int i=2;i<=all;++i){
if(t[i].v!=t[i-1].v){
++zy;
}
if(t[i].p%2==1){
xs[(t[i].p+1)/2]=zy;
}
else{
ys[t[i].p/2]=zy;
}
ma[zy]=t[i].v;
}
for(int i=1;i<=n;++i){
++a[xs[i]];
--a[ys[i]];
}
for(int i=1;i<=zy;++i){
a[i]+=a[i-1];
}
sufmax[zy]=a[zy];
for(int i=zy-1;i>=1;--i){
sufmax[i]=max(a[i],sufmax[i+1]);
}
int ans=*max_element(a+1,a+zy+1);
for(int i=1;i<=zy;++i){
if(Left[a[i]]>2000000000){
Left[a[i]]=i;
}
}
for(int i=ans-1;i>=1;--i){
Left[i]=min(Left[i],Left[i+1]);
}
for(int i=zy;i>=1;--i){
if(sufmax[i]!=sufmax[i-1]){
for(int j=sufmax[i]+1;j<=sufmax[i-1];++j){
Right[j]=i;
}
}
}
ll sum=0;
for(int i=1;i<=ans;++i){
sum+=(ll)(ma[Right[i]]-ma[Left[i]]);
}
printf("%d %lld\n",ans,sum);
}
return 0;
}

【贪心】hdu6180 Schedule的更多相关文章

  1. 贪心-Course Schedule III

    2020-02-01 21:37:39 问题描述: 问题求解: 对于课程来说截止时间在前面的肯定需要优先安排,所以首先需要将courses按照deadline进行排序. 然后只需要不断的加入当前的课程 ...

  2. 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 < ...

  3. POJ 3553 Task schedule【拓扑排序 + 优先队列 / 贪心】

    Task schedule Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 515 Accepted: 309 Special J ...

  4. Schedule HDU - 6180 (multiset , 贪心)

    There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). Ther ...

  5. 2017多校第10场 HDU 6180 Schedule 贪心,multiset

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...

  6. 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)

    F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  7. codeforces 480A A. Exams(贪心)

    题目链接: A. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. POJ 1456 Supermarket 区间问题并查集||贪心

    F - Supermarket Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Sub ...

  9. Ferry Loading II_贪心

    Description Before bridges were common, ferries were used to transport cars across rivers. River fer ...

随机推荐

  1. VS开发工具 因插件问题导致 已停止工作 解决办法

    解决方案如下:No1. 开始-->所有程序-->Microsoft Visual Studio 2012-->Visual Studio Tools-->VS2012 开发人员 ...

  2. fragment+tabhost与viewpager

    学到哪里写到哪里吧 A.viewpager a.用V4包中的fragment,activity继承FragmentActivity b.布局中加入<android.support.v4.view ...

  3. Pythone3 sys模块

    1.sys.argv 可以实现从程序外部向程序传递参数2.sys.exit() 程序中间退出,exit(0)正常退出,其他为异常退出3.sys.getdefaultencoding() 获取系统编码方 ...

  4. Deep Learning基础--26种神经网络激活函数可视化

    在神经网络中,激活函数决定来自给定输入集的节点的输出,其中非线性激活函数允许网络复制复杂的非线性行为.正如绝大多数神经网络借助某种形式的梯度下降进行优化,激活函数需要是可微分(或者至少是几乎完全可微分 ...

  5. 2015多校第6场 HDU 5354 Bipartite Graph CDQ,并查集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5354 题意:求删去每个点后图是否存在奇环(n,m<=1e5) 解法:很经典的套路,和这题一样:h ...

  6. yum安装的Apache的各种配置文件的位置

    //配置文件 /etc/httpd/conf /etc/httpd/conf.d /etc/httpd/conf.d/README /etc/httpd/conf.d/proxy_ajp.conf / ...

  7. python traceback

    1. Python中的异常栈跟踪 之前在做Java的时候,异常对象默认就包含stacktrace相关的信息,通过异常对象的相关方法printStackTrace()和getStackTrace()等方 ...

  8. linux命令(44):date命令

    1.命令格式: date [参数]... [+格式] 2.命令功能: date 可以用来显示或设定系统的日期与时间. 3.命令参数: 必要参数: %H 小时(以00-23来表示). %I 小时(以01 ...

  9. (转载)IntelliJ IDEA 自动导入包 快捷方式

    原文地址:IntelliJ IDEA 自动导入包 快捷方式 idea可以自动优化导入包,但是有多个同名的类调用不同的包,必须自己手动Alt+Enter设置 设置idea导入包 勾选标注 1 选项,In ...

  10. mac下谷歌chrome浏览器的快捷键

    1. 标签页和窗口快捷键 ⌘-N 打开新窗口. ⌘-T 打开新标签页. ⌘-Shift-N 在隐身模式下打开新窗口. 按 ⌘-O,然后选择文件. 在 Chrome 浏览器中打开计算机中的文件. 按住  ...