zoukankan      html  css  js  c++  java
  • HDU 4864 Task

    贪心,排序,二分。。。

    对x排序。

    对于每个task,先把时间满足它的机器放入集合中,在二分找能处理它的最小等级的机器。

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <set>
    using namespace std;
    
    const int maxn = 200010;
    
    struct node {
        int x,y;
        int price;
        int mak;
    }mt[maxn];
    
    bool cmp (const node &x,const node &y){
        if (x.x!=y.x)   return x.x>y.x;
        if (x.y!=y.y)   return x.y>y.y;
        return x.mak>y.mak;
    }
    
    int main (){
        int n,m;
        while (~scanf ("%d%d",&n,&m)){
            for (int i=0;i<n;i++){
                scanf ("%d%d",&mt[i].x,&mt[i].y);
                mt[i].mak=1;
            }
            for (int i=0;i<m;i++){
                scanf ("%d%d",&mt[n+i].x,&mt[n+i].y);
                mt[n+i].price=500*mt[n+i].x+2*mt[n+i].y;
                mt[n+i].mak=0;
            }
            sort (mt,mt+n+m,cmp);
            multiset<int> s;
            multiset<int> :: iterator it;
            int ans=0;
            int flag=0;
            long long sum=0;
            s.clear ();
            for (int i=0;i<n+m;i++){//cout<<mt[i].y<<endl;
                if (mt[i].mak)
                    s.insert (mt[i].y);
                else if (!s.empty()){
                    it=s.lower_bound (mt[i].y);
                    if (it==s.end ())
                        continue ;
                    flag--;
                    ans++;
                    sum+=mt[i].price;//cout<<sum<<endl;
                    s.erase (it);
                }
            }//cout<<mt[0].mak;
            printf ("%d %I64d
    ",ans,sum);
        }
        return 0;
    }
  • 相关阅读:
    负载均衡——LVS DR模式
    Java之BigDecimal详解
    Spring AOP代理对象创建流程
    spring aop切面不生效
    aspectj-autoproxy Controller未生效解决方案
    jvm参数分类
    dubbo优雅停机
    Dubbo 协议注意项
    dubbo provider
    查找java_home的安装路径
  • 原文地址:https://www.cnblogs.com/gfc-g/p/3863148.html
Copyright © 2011-2022 走看看