• USACO Section 1.2PROB Miking Cows


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

    /*
    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
    ",cont_time,idle_time);
        return 0;
    }
  • 相关阅读:
    如何在magento添加推荐分类
    Apache和iis的冲突处理
    怎么在windows7下搭建服务器
    centos dns配置
    wget net-tools
    centos7 ip地址设置
    centos 7 u盘安装
    centos7 u盘启动路径设置
    screen 命令
    lnmp重置mysql密码
  • 原文地址:https://www.cnblogs.com/jusonalien/p/4061005.html
Copyright © 2020-2023  润新知