码迷,mamicode.com
首页 > 其他好文 > 详细

usaco Milking Cows

时间:2015-08-26 17:16:53      阅读:138      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!