【贪心】hdu6180 Schedule
题意:给你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的更多相关文章
- 贪心-Course Schedule III
2020-02-01 21:37:39 问题描述: 问题求解: 对于课程来说截止时间在前面的肯定需要优先安排,所以首先需要将courses按照deadline进行排序. 然后只需要不断的加入当前的课程 ...
- 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 < ...
- POJ 3553 Task schedule【拓扑排序 + 优先队列 / 贪心】
Task schedule Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 515 Accepted: 309 Special J ...
- Schedule HDU - 6180 (multiset , 贪心)
There are N schedules, the i-th schedule has start time si and end time ei (1 <= i <= N). Ther ...
- 2017多校第10场 HDU 6180 Schedule 贪心,multiset
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...
- 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)
F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...
- codeforces 480A A. Exams(贪心)
题目链接: A. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- POJ 1456 Supermarket 区间问题并查集||贪心
F - Supermarket Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- Ferry Loading II_贪心
Description Before bridges were common, ferries were used to transport cars across rivers. River fer ...
随机推荐
- bzoj 3035 二分答案+二分图最大匹配
大原来做的一道题,偷懒直接粘的原来的程序 http://www.cnblogs.com/BLADEVIL/p/3433520.html /******************************* ...
- bootstrap-table组合表头
1.效果图 2.html代码 <table id="table"></table> 3.javascript代码 $("#table") ...
- cart回归树算法过程
回归树:使用平方误差最小准则 训练集为:D={(x1,y1), (x2,y2), …, (xn,yn)}. 输出Y为连续变量,将输入划分为M个区域,分别为R1,R2,…,RM,每个区域的输出值分别为: ...
- 某p2p存在通用上传漏洞
google链接查找: inurl:shouyi.asp inurl:itemlist_xq.asp?id= 很多存在Fckeditor上传链接: FCKeditor/editor/filemanag ...
- [Leetcode Week13]Palindrome Partitioning
Palindrome Partitioning 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/palindrome-partitioning/desc ...
- Git常规配置与基本用法
Git环境配置 一. 全局配置 1. 配置文件 git全局配置文件.gitconfig默认在当前系统用户文件夹下,window可运行%USERPROFILE%查找,Mac系统在cd ~查找. 具体配置 ...
- exit() _exit() 函数区别
exit(): --stdlib.h (1) 所有使用atexit()注册的函数,将会被以注册相反的顺序调用: (2) 所有打开的输出流被刷新,并且关闭流: (3) 使用tmpfile()创建的文件将 ...
- 使用Redirector插件解决googleapis公共库加载的问题【转】
转自:http://www.cnblogs.com/kari/p/5860371.html 最近访问一些面向国外的网站总是会出现ajax.googleaips.com无法加载的情况.以下为加载stac ...
- Django 国内最全教程
https://code.ziqiangxuetang.com/django/django-tutorial.html
- linux和ubuntu防火墙相关命令
1.永久有效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2.即刻生效 开启: service iptables start 关闭: se ...