题意:给你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. 微软Azure DevOps 使用docker 持续集成 dotnet

    azure 环境设置 登录azure 地址 https://dev.azure.com/ 使用微软账号就可以进行登录. 点击右上角新建项目 项目信息,尽量用小写 创建项目 修改默认的dockerfil ...

  2. js中的for in 循环

    1.数组 使用for in 遍历数组时,其索引被视为对象的属性,从而直接输出数组的索引 var arr = ["a","b","c"]; f ...

  3. linux下暴力破解工具hydra【转】

    一.简介 Number one of the biggest security holes are passwords, as every password security study shows. ...

  4. ms17-010 攻击win7漏洞复现

    只是为了好玩重新写一篇.利用还是很简单的. 将下载下来的rb放置在:/usr/share/metasploit-framework/modules/exploits/windows/smb/ 目录下 ...

  5. Python3 hashlib模块和hmac 模块(加密)

    hashlib 是一个提供了一些流行的hash算法的 Python 标准库.其中所包括的算法有 md5, sha1, sha224, sha256, sha384, sha512等常用算法 MD5加密 ...

  6. 64_m2

    mimetic-devel-0.9.8-7.fc26.i686.rpm 12-Feb-2017 05:40 288474 mimetic-devel-0.9.8-7.fc26.x86_64.rpm 1 ...

  7. 菜鸟学习nodejs--Socket.IO即时通讯

    https://blog.csdn.net/lovemenghaibin/article/details/51263774

  8. C语言的小括号----其实是逗号运算符

    比如下面的代码: #include <stdio.h> void fun() { int a, b, c, d; a = (, b = ); c = (, ); d = (, ); pri ...

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

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

  10. UML基础

    UML基础系列:类图   类图描述系统中类的静态结构,它不仅定义系统中的类,描述类之间的联系,如关联.依赖.聚合等,还包括类的内部结构(类的属性和操作).类图描述的是静态关系,在系统的整个生命周期中都 ...