首页 > 其他 > 详细

uvalive 7423

时间:2017-04-06 23:12:15      阅读:342      评论:0      收藏:0      [点我收藏+]

贪心,前几天刚做过类似的题,以为能变形出来,结果还是差一点成功,哎,还是我太渣

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn=300005;
typedef struct note
{
    int x,y;
    bool operator <(const note &p)
    {
        return x<p.x;
    }
};
note a[maxn];
priority_queue< int,vector<int>,greater<int> > q;
int n,m;
int main()
{
    while(~scanf("%d%d",&n,&m))
    {    int ans=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
            a[i].y+=a[i].x;
        }
        sort(a,a+n);
        while(q.size()) q.pop();
        for(int i=0;i<n;i++)
        {
            while(q.size()&&q.top()+m<a[i].x)//最神奇地方,当时我就是在这里想用for,结果超时,但一个while的队列就解决了让我很难受
                q.pop();//下个人来的时候,电脑都锁了
            if(q.empty()||q.top()>a[i].x)
            {
                ans++;
                q.push(a[i].y);//下个人来的时候电脑有人在用,再开一台
            }
            else
            {
                q.pop();
                q.push(a[i].y);//下个人来的时候人走了,但电脑没锁
            }
        }
        printf("%d\n",n-ans);
    }
    return 0;
}

 

uvalive 7423

原文:http://www.cnblogs.com/Wangwanxiang/p/6675941.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!