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;
    }
    
  • 相关阅读:
    mysql对表操作的各种语句
    Map遍历两种方式
    hibernate3
    Spring、mybaits整合
    mybaits注解
    mybaits 框架运用
    mybatis入门
    限制文本框字符数
    Unity3D Mathf函数
    Unity3d 粒子工具注释
  • 原文地址:https://www.cnblogs.com/kun-/p/10659640.html
Copyright © 2011-2022 走看看