题意:给你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. HDU 2084 数塔 (dp)

    题目链接 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数 ...

  2. perl输出重定向

    use utf8; open A, ">&STDOUT"; open STDOUT, ">AA.txt"; print STDOUT 'AB ...

  3. 【字符串处理算法】字符串包含的算法设计及C代码实现【转】

    转自:http://blog.csdn.net/zhouzhaoxiong1227/article/details/50679587 版权声明:本文为博主原创文章,对文章内容有任何意见或建议,欢迎与作 ...

  4. appium===登陆应用的案例

    import time import os from appium import webdriver from selenium.webdriver.support.ui import WebDriv ...

  5. uoj#35 后缀排序(后缀数组模版)

    #include<bits/stdc++.h> #define N 100005 using namespace std; char s[N]; int a[N],c[N],t1[N],t ...

  6. python爬虫实战——5分钟做个图片自动下载器

      python爬虫实战——图片自动下载器 制作爬虫的基本步骤 顺便通过这个小例子,可以掌握一些有关制作爬虫的基本的步骤. 一般来说,制作一个爬虫需要分以下几个步骤: 分析需求(对,需求分析非常重要, ...

  7. [bugfix]copy属性参数将NSMutableArray变为NSArray类型

    问题:NSMutableArray 声明为 copy 属性参数后即使接受NSMutableArray变量依然为NSArray变量 测试: 属性申明为: 1 @property (nonatomic, ...

  8. ES Java 客户端

    标签(空格分隔): ES Java 客户端 节点客户端(node client): 节点客户端本身也是一个ES节点(一般不保存数据,不能成为主节点),它能以无数据节点身份加入到集群中.因为它是集群环境 ...

  9. [知识复习] C语言文件读写

    文件打开 fopen() 返回FILE* 对象,如果打开失败返回NULL,错误代码存入errno中 FILE *fopen( const char * filename, const char * m ...

  10. PL/SQL 11.6 注册码

    PL/SQL Developer 下载地址:Download PL/SQL Developer 11.0.6 注册码 Product Code:4t46t6vydkvsxekkvf3fjnpzy5wb ...