题意:给你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. bzoj 2165 DP

    首先如果不考虑数据范围的话,因为每一层都是等效的,所以我们可以用w[i][j][k]来表示在某一层的j位置,称作i次电梯到k位置,最多上升多少层,那么我们可以比较容易的写出转移,因为m十分大,i可能与 ...

  2. deepin安装metasploit

    [1]安装metasploit 1.curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/tem ...

  3. Python3 高阶函数

    高阶函数 (满足其一就是:(1)一个函数名作为另一个函数的形参:(2)返回值包含函数名;不修改函数的调用方式) 1.一个函数名作为另一个函数的形参 输出结果: 2.返回值包含函数名;不修改函数的 输出 ...

  4. Python基础===使用virtualenv创建一个新的运行环境

    virtualenv简直是一个神器,以ubuntu环境为例, 先安装virtualenv 然后执行如下命令: 多版本创建env的方式: virtualenv 虚拟环境文件目录名 python=pyth ...

  5. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6152 Friend-Graph 暴暴暴暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6152 题意:判定一个无向图是否有三个点的团或者三个点的独立集. 解法:Ramsey theorem,n ...

  6. C json实战引擎 三 , 最后实现部分辅助函数

    引言 大学读的是一个很时髦的专业, 学了四年的游戏竞技. 可惜没学好. 但认真过, 比做什么都认真. 见证了  ...... 打的所有游戏人物中 分享一位最喜爱 的 “I've been alone ...

  7. vue css动画

    .toggle-cart-enter-active, .toggle-cart-leave-active { transition: all .3s ease-out; } .toggle-cart- ...

  8. 给定一列数字将其平移n位

    原题的意思是给定一个指定长度的数组,然后接受一个数字m,将原数组前m位移动到最后,且顺序不变. 看到这个题,想到的第一个方法就是在用一个数组来储存改变后的数字,代码如下 int func(){ int ...

  9. Thinking in java基础之集合框架(转载)

    集合简介(容器)把具有相同性质的一类东西,汇聚成一个整体,就可以称为集合,例如这里有20个苹果,我们把每一个苹果当成一个东西(一个对象),然后我们借用袋子把这20个苹果装起来,而这个袋子就是集合(也叫 ...

  10. [你必须知道的.NET]第二十六回:认识元数据和IL(下)

    发布日期:2009.03.04 作者:Anytao © 2009 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 说在,开篇之前 书接上回: 第二十四回:认识元数据和IL(上), ...