首页 > 其他 > 详细

usaco Milking Cows

时间:2015-08-26 17:16:23      阅读:83      评论:0      收藏:0      [点我收藏+]
/*
ID: modengd1
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <stdio.h>
#include <queue>
struct node
{
    int time;
    int O;
    node(int t,int o)
    {
        time=t;
        O=o;
    }
    node(){}
    bool friend operator <(node n1,node n2)
    {
        return n1.time>n2.time;
    }
};
using namespace std;
int N;
int main()
{
    freopen("milk2.in","r",stdin);
    freopen("milk2.out","w",stdout);
    int a,b;
    int ans1=0,ans2=0;
    int begint;
    int cows=0;
    scanf("%d",&N);
    priority_queue<node> Q;
    for(int i=0;i<N;i++)
    {
        scanf("%d%d",&a,&b);
        Q.push(node(a,1));
        Q.push(node(b,-1));
    }
    node now=Q.top();
    begint=now.time;
    while(!Q.empty())
    {

        now=Q.top();
        Q.pop();
        if(cows==0)
        {
             ans1=max(ans1,now.time-begint);
             begint=now.time;
        }
        cows+=now.O;
        if(cows==0)
        {
            ans2=max(ans2,now.time-begint);
            begint=now.time;
        }
    }
    cout<<ans2<<‘ ‘<<ans1<<endl;
    return 0;
}

  

usaco Milking Cows

原文:http://www.cnblogs.com/modengdubai/p/4760714.html

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