zoukankan      html  css  js  c++  java
  • POJ

    原题链接

    题意:给定每头牛的吃草的开始时间和结束时间,求最少需要的畜栏数

    #include <algorithm>
    #include <cstdio>
    #include <queue>
    using namespace std;
    const int N = 5e4+10;
    struct node{
        int st, ed, id;
        bool operator < (const node & a) const{
            return st < a.st;
        }
    }p[N];
    struct node1{
        int ed, id, id1;
        bool operator < (const node1 & a) const{
            return ed > a.ed;
        }
    };
    struct node2{
        int ans, id;
        bool operator < (const node2 & a) const{
            return id < a.id;
        }
    };
    int main(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt", "r", stdin);
    #endif //ONLINE_JUDGE
        int n, a, b, ans = 0;
        scanf("%d", &n);
        for(int i = 0; i < n; i++){
            scanf("%d%d", &a, &b);
            p[i] = (node){a, b, i};
        }
        sort(p, p + n);
        priority_queue<node1> q;
        vector<node2> qq;
        ans++;
        q.push((node1){p[0].ed, ans, p[0].id});
        qq.push_back((node2){ans, q.top().id1});
        for(int i = 1; i < n; i++){
            if(p[i].st <= q.top().ed){
                ans++;
                q.push((node1){p[i].ed, ans, p[i].id});
                qq.push_back((node2){ans, p[i].id});
            }
            else{
                q.push((node1){p[i].ed, q.top().id, p[i].id});
                qq.push_back((node2){q.top().id, p[i].id});
                q.pop();
            }
        }
        printf("%d
    ", ans);
        sort(qq.begin(), qq.end());
        for(int i = 0; i < qq.size(); i++){
            printf("%d
    ", qq[i]);
        }
        return 0;
    }
    
  • 相关阅读:
    Ehcache缓存配置
    spring3使用task:annotation-driven开始定时
    Constructor >> @Autowired >> @PostConstruct
    面试转载
    阿里面试:MYSQL的引擎区别
    Redis的主从复制的原理介绍
    微服务的调用链
    java的零拷贝机制
    存储过程与触发器面试
    ABA问题
  • 原文地址:https://www.cnblogs.com/kun-/p/10659640.html
Copyright © 2011-2022 走看看