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

USACO Section 1.2PROB Miking Cows

时间:2014-10-30 01:46:13      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   for   sp   on   art   cti   html   

贪心做过去,先对每个时间的左边点进行排序,然后乱搞,当然线段树也可以做

/*
ID: jusonal1
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
struct node{
    int left;
    int right;
    bool operator<(const node& T)const{
        return left < T.left;
    }
};
int n;
const int maxn = 5000 + 100;
node cow[maxn];
int main () {
    freopen("milk2.in","r",stdin);
    freopen("milk2.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1;i <= n;++i) scanf("%d%d",&cow[i].left,&cow[i].right);
    sort(cow + 1,cow + 1 + n);
    int cont_time = cow[1].right - cow[1].left,idle_time = 0;
    int start = 0,end = 0;
    int blank_sum = 0;
    start = cow[1].left;
    end   = cow[1].right;
    for(int i = 1;i <= n;++i){
        if(cow[i].left > end ){
            idle_time = max(idle_time,cow[i].left - end);
            start = cow[i].left;
            end   = cow[i].right;
        }
        else if(cow[i].right > end){
            end = cow[i].right;
        }
        cont_time = max(cont_time,end - start);
    }
    printf("%d %d\n",cont_time,idle_time);
    return 0;
}

USACO Section 1.2PROB Miking Cows

标签:io   os   ar   for   sp   on   art   cti   html   

原文地址:http://www.cnblogs.com/jusonalien/p/4061005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!