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. JQuery-Ajax后台提交数据与获取数据 Java代码

    function jqajax(){ var urlName = $("#urlName").val(); var urla = $("#url").val() ...

  2. Struts2+Hibernate实现图书管理系统

    效果图 部分代码 Books.java package entity; import java.util.Date; public class Books { //书籍编号 private Strin ...

  3. 自动化测试===Httprunner测试框架介绍

    项目地址: https://github.com/HttpRunner/HttpRunner 中文手册: http://cn.httprunner.org/ 首先是环境搭建: pip install ...

  4. 安全测试===sqlmap

    本文转自:https://www.secpulse.com/archives/4213.html   鉴于很多新手对sqlmap的用法不是很熟悉 很多常用sqlmap的也不一定完全会用sqlmap 特 ...

  5. selenium.webdriver.common.keys 模块中常用的变量

    表11-5 selenium.webdriver.common.keys 模块中常用的变量属性 含义Keys.DOWN, Keys.UP, Keys.LEFT,Keys.RIGHT 键盘箭头键Keys ...

  6. C++中多线程与Singleton的那些事儿

    前言 前段时间在网上看到了个的面试题,大概意思是如何在不使用锁和C++11的情况下,用C++实现线程安全的Singleton. 看到这个题目后,第一个想法就是用Scott Meyer在<Effe ...

  7. [LabVIEW架构]ActorFramework(一)

    前言 小黑结婚回来第二周了,每天忙于程序设计,时间比较紧张,所以文章一直没出来,也算憋大招了. 近期小黑将与大家一起认识一下ActorFramework,既是对自己一段时间写AF程序的总结,也是梳理, ...

  8. leetcode 之LRU Cache(26)

    很实际的一道题.定义一个双向链表list,方便插入和删除:定义一个哈希表,方便查找. 具体的,哈希表存放每个结点的key和它对应的结点的地址:访问结点时,如果结点存在,则将其交换到头部,同是更新哈希表 ...

  9. MiCode108 猜数字

    Description 相传,十八世纪的数学家喜欢玩一种猜数字的小游戏,规则如下: 首先裁判选定一个正整数数字 N (2 \leq N \leq 200)N(2≤N≤200),然后选择两个不同的整数X ...

  10. ExecutorService 用例

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Tes ...