4425: [Nwerc2015]Assigning Workstations分配工作站

Description

Penelope is part of the admin team of the newly built supercomputer. Her job is to assign workstations to the researchers who come here to run their computations at the supercomputer.
Penelope is very lazy and hates unlocking machines for the arriving researchers. She can unlock the machines remotely from her desk, but does not feel that this menial task matches her qualifications. Should she decide to ignore the security guidelines she could simply ask the researchers not to lock their workstations when they leave, and then assign new researchers to workstations that are not used any more but that are still unlocked. That way, she only needs to unlock each workstation for the first researcher using it, which would be a huge improvement for Penelope.
 
Unfortunately, unused workstations lock themselves automatically if they are unused for more than mm minutes. After a workstation has locked itself, Penelope has to unlock it again for the next researcher using it. Given the exact schedule of arriving and leaving researchers, can you tell Penelope how many unlockings she may save by asking the researchers not to lock their workstations when they leave and assigning arriving researchers to workstations in an optimal way? You may assume that there are always enough workstations available.
Input
The input consists of:
one line with two integers n (1≤n≤300000), the number of researchers, and m (1≤m≤10^8), the number of minutes of inactivity after which a workstation locks itself;
n lines each with two integers a and s (1≤a,s≤10^8), representing a researcher that arrives after a minutes and stays for exactly s minutes.
Output
Output the maximum number of unlockings Penelope may save herself.
佩内洛普是新建立的超级计算机的管理员中的一员。 她的工作是分配工作站给到这里来运行他们的计算研究任务的研究人员。
佩内洛普非常懒惰,不喜欢为到达的研究者们解锁机器。 她可以从在她的办公桌远程解锁这些机器,但她并不觉得这卑贱的任务配得上她,所以她决定忽略安全指南偷偷懒。她可以直接地要求,研究者在他们离开时不用锁定自己的工作站,然后把未在使用且还在未锁定状态的工作站分配给新来的研究人员。 这样,她只需要为每一个工作站第一次被使用所属的研究员解锁工作站,这对佩内洛普的工作来说是一个巨大的改善。
不幸的是,如果一个工作站在未锁定且没被使用的状态下超过m分钟,会自动锁定自己,佩内洛普必须为使用它的下一个研究员再次打开它。 鉴于抵达和离开的研究人员的确切时间表,你可以告诉佩内洛普,要求研究者在离开时不锁定工作站最多可以使她节约多少次的解锁工作。你可以认为这儿总是有足够的可用工作站。

Input

一行两个整数n (1≤n≤300000) 研究员的数量n,以及 m (1≤m≤100000000) 工作站在未锁定且没被使用的状态下超过m分钟会自动锁定。
下面的n行,每一行两个整数a与s (1≤a,s≤100000000) 表示一个研究员在第a分钟时到达以及待了s分钟后离开。

Output

输出研究者在离开时不锁定工作站最多可以使她节约多少次解锁工作。

Sample Input

Sample Input 1
3 5
1 5
6 3
14 6
Sample Input 2
5 10
2 6
1 2
17 7
3 9
15 6

Sample Output

Sample Output 1
2
Sample Output 2
3
题解:
贪心。还是比较明显的。。
我们维护一个小跟堆,存p[i].a+p[i].b+m
如果堆中的元素值<当前的p[i].a,那么很明显它没什么用了(反正都要增加一次次数)。
找到第一个>=p[i].a的元素,再判断。。
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=;
#define p1 (p<<1)
#define p2 (p<<1|1)
struct node
{
int a,b;
}p[N];
int n,m,i,k,ans,t[N];
bool cmp(const node&x,const node&y)
{
return x.a<y.a;
}
void up(int p)
{
while((p>>)>)
{
if(t[p]<t[p>>])
{
swap(t[p],t[p>>]);
p>>=;
} else break;
}
}
void down(int p)
{
int x;
while(p1<=k)
{
if(p2<=k)
{
if(t[p1]<t[p2]) x=p1;else x=p2;
} else x=p1;
if(t[p]>t[x])
{
swap(t[p],t[x]);
p=x;
} else break;
}
}
int main()
{
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
scanf("%d%d",&p[i].a,&p[i].b);
sort(p+,p+n+,cmp);
k=;ans=;t[]=p[].a+p[].b+m;
for(i=;i<=n;i++)
{
while(k>&&t[]<p[i].a)
{
t[]=t[k--];
down();
}
if(t[]>=p[i].a&&t[]-m<=p[i].a)
{
ans++;
t[]=t[k--];
down();
}
t[++k]=p[i].a+p[i].b+m;
up(k);
}
cout<<ans;
return ;
}

4425: [Nwerc2015]Assigning Workstations分配工作站的更多相关文章

  1. BZOJ 4425: [Nwerc2015]Assigning Workstations分配工作站

    难度在于读题 #include<cstdio> #include<algorithm> #include<queue> using namespace std; p ...

  2. 【bzoj4425】[Nwerc2015]Assigning Workstations分配工作站 贪心+堆

    题目描述 佩内洛普是新建立的超级计算机的管理员中的一员. 她的工作是分配工作站给到这里来运行他们的计算研究任务的研究人员. 佩内洛普非常懒惰,不喜欢为到达的研究者们解锁机器. 她可以从在她的办公桌远程 ...

  3. 【贪心】【堆】Gym - 101485A - Assigning Workstations

    题意:有n个人,依次来到机房,给你他们每个人的到达时间和使用时间,你给他们分配电脑,要么新开一台, 要么给他一台别人用完以后没关的.一台电脑会在停止使用M分钟后自动关闭.让你最大化不需要新开电脑的总人 ...

  4. Assigning Workstations

    题目链接:http://vjudge.net/contest/127404#problem/A /* 给你n个数字,让你找出一个最小的数字,这个数字不在这些数字中出现的 ,注意:这个数字如果各个位上的 ...

  5. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  6. word20161213

    journal queue / 日志队列 journal quota / 日志配额 junction point / 交叉点 KDC, Key Distribution Center / 密钥分发中心 ...

  7. Gym101485: NWERC 2015(队内第6次训练)

    A .Assigning Workstations 题意:给定N个人的工作时间和工作时长,我们可以假设有无数台工作机器,如果一台机器超过M时间未使用就会关闭,那么我们怎么安排机器的使用,使得需要开启机 ...

  8. 用route命令解决多出口的问题

    网络已经走进了我们的生活.工作.学习之中,大多数单位.公司都已经连接到了Internet.但是,因为各种原因,有这样一个问题存在.就是:这些单位即有到公网(Internet)的出口连接,也有到专网(单 ...

  9. Five things that make Go fast-渣渣翻译-让GO语言更快的5个原因

    原文地址:https://dave.cheney.net/2014/06/07/five-things-that-make-go-fast 翻译放在每个小段下面 Anthony Starks has ...

随机推荐

  1. Maven学习笔记(一)

    我们暂且可以把Maven理解成是一个项目构建与依赖管理的工具   为什么选用maven? 约定(惯例)优先原则,默认限定了项目目录结构 提供三方依赖管理(解决了依赖维护的问题) 提供了一致的项目构建管 ...

  2. 集合框架源码学习之ArrayList

    目录: 0-0-1. 前言 0-0-2. 集合框架知识回顾 0-0-3. ArrayList简介 0-0-4. ArrayList核心源码 0-0-5. ArrayList源码剖析 0-0-6. Ar ...

  3. c语言中的size_t

    size_t unsigned int 类型,无符号,它的取值没有负数.用来表示 参数/数组元素个数,sizeof 返回值,或 str相关函数返回的 size 或 长度.sizeof 操作符的结果类型 ...

  4. hadoop入门学习

    hadoop入门学习:http://edu.csdn.net/course/detail/1397hadoop hadoop2视频:http://pan.baidu.com/s/1o6uy7Q6HDF ...

  5. Linux 入门记录:二十、Linux 包管理工具 YUM

    一.YUM(Yellowdog Updater, Modified) 1. YUM 简介 RPM 软件包形式管理软件虽然方便,但是需要手动解决软件包的依赖问题.很多时候安装一个软件首先需要安装 1 个 ...

  6. web优化的方法

    缓存(减小对服务器.数据库的压力) 生成静态页面(区别于缓存,数据量太大用“缓存”不利) URL重写(SEO,搜索引擎的优化) ajax的优化(SEO) <meta content=“” nam ...

  7. [linux]通过ssh远程设定各服务器时间,从而实现集群时间同步

    #!/usr/bin/env bash #all hosts should to sync time, all hosts should no password login echo other sy ...

  8. 【mongo】用户添加、导入数据库、连接VUE

    添加用户 1.安装mongo时最好用apt-get install  因为这样可以省去很多麻烦,比如一些环境变量,还有一些文档路径等等的问题 2.确认一下自己的mongodb和mongodb-clie ...

  9. LeetCode解题报告—— Median of Two Sorted Arrays

    There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...

  10. Django基础之form组件

    Form介绍 我们之前在HTML页面中利用form表单向后端提交数据时,都会写一些获取用户输入的标签并且用form标签把它们包起来. 与此同时我们在好多场景下都需要对用户的输入做校验,比如校验用户是否 ...