zoukankan      html  css  js  c++  java
  • POJ 3614 (贪心)

    原题链接

    思路:把牛的最小值升序排序,防晒霜的防晒强度升序排序。如果牛最小承受小于防晒霜的,让牛的最大防晒进队。然后判断队列里面牛的最大承受大于防晒霜,就答案加1

    #include<cstdio>
    #include<queue>
    #include<algorithm>
    using namespace std;
    const int N = 1e5+10;
    int n, m;
    struct node{
        int a, b;
        bool operator < (const node & a1) const{
            return a < a1.a;
        }
    }cow[N], bot[N];
    int main(){
        #ifdef ONLINE_JUDGE
        #else
            freopen("in.txt", "r", stdin);
        #endif // ONLINE_JUDGE
        int ans  = 0;
        scanf("%d%d", &n, &m);
        for(int i = 1; i <= n; i++){
            scanf("%d%d", &cow[i].a, &cow[i].b);
        }
        for(int i = 1; i <= m; i++){
            scanf("%d%d", &bot[i].a, &bot[i].b);
        }
        sort(cow + 1, cow + 1 + n);
        sort(bot + 1, bot + 1 + m);
        priority_queue<int, vector<int>, greater<int> > q;
        for(int i = 1, j = 1; i <= m; i++){
            while(j <= n && cow[j].a <= bot[i].a){
                q.push(cow[j].b);
                j++;
            }
            while(!q.empty() && bot[i].b){
                int t = q.top();
                q.pop();
                if(t < bot[i].a) continue;
                ans++;
                bot[i].b--;
            }
        }
        printf("%d
    ", ans);
        return 0;
    }
    
    
    
  • 相关阅读:
    Linux命令——mkdir
    UNIX 高手的 10 个习惯
    Linux命令——pwd
    Linux命令——cd命令
    Linux命令——ls命令
    denyhost安装脚本
    三台服务器无需密码相互访问
    字符串方法
    nginx简易安装
    shell 条件判断语句整理
  • 原文地址:https://www.cnblogs.com/kun-/p/10643654.html
Copyright © 2011-2022 走看看