zoukankan      html  css  js  c++  java
  • 【NWERC 2015-A】Elementary Math 优先队列STL

    题目链接:https://vjudge.net/problem/Gym-101485A

    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.

    Sample Input 1

    3 5
    1 5
    6 3
    14 6

    Sample Output 1

    2

    Sample Input 2

    5 10
    2 6
    1 2
    17 7
    3 9
    15 6

    Sample Output 2

    3

    烫脚中文题意

    有一个机房,有n个人过来用机子,网管每次都得去开机子,暴躁网管不想去开机子,就让别人用好了不要关。每次用完后有m分钟机子不会关,请问网管能少开多少次机子。

    思路

    给个优先队列,元素是结束时间,从小到大排。

    若头元素的时间+m小于此时的a,则满足,先弹出头元素,再塞入新的结束时间。

    若头元素的时间大于此时的a或者队列为空时,塞入结束时间。

    AC代码

    (在队友的提交账号上,哪天扒下来。

  • 相关阅读:
    欧拉计划之题目7:找出第10001个质数
    DShow实现一个avi视频的播放(含有个人解释和注释)
    DirectX 9 SDK安装后在vs2010里编译BaseClasses出错问题解决方法
    C#内存占用大量资源的解决办法
    C#读写ini文件操作
    【Java】编程技术经典书籍列表
    【数据库_Mysql】查询当前年份的sql
    【数据库_Mysql】MySQL动态语句 if set choose where foreach trim
    【JavaScript】20款漂亮的css字体
    【数据库_Mysql】<foreach>标签在Mysql中的使用
  • 原文地址:https://www.cnblogs.com/tudouuuuu/p/11569610.html
Copyright © 2011-2022 走看看