zoukankan      html  css  js  c++  java
  • bzoj1691/luogu2869 [USACO07DEC]挑剔的美食家 (STL::set)

    给牛和草都按价格排序,然后贪心地把草给牛(就是尽量给满足价格的、要求的美味度最高但不超过这个草的美味度的牛)

    这个可以用一个平衡树来维护,偷懒直接用multiset了

     1 #include<bits/stdc++.h>
     2 #define pa pair<int,int>
     3 #define ll long long
     4 using namespace std;
     5 const int maxn=100010;
     6 
     7 inline ll rd(){
     8     ll x=0;char c=getchar();int neg=1;
     9     while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
    10     while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    11     return x*neg;
    12 }
    13 
    14 multiset<int> st;
    15 int N,M;
    16 pa cow[maxn],gra[maxn];
    17 
    18 int main(){
    19     //freopen("1691.in","r",stdin);
    20     int i,j,k;
    21     N=rd();M=rd();
    22     for(i=1;i<=N;i++){
    23         cow[i].first=rd(),cow[i].second=rd();
    24     }for(i=1;i<=M;i++){
    25         gra[i].first=rd(),gra[i].second=rd();
    26     }
    27     sort(cow+1,cow+N+1);sort(gra+1,gra+M+1);
    28     ll ans=0;int num=0;
    29     for(i=1,j=1;i<=M&&num<=N;i++){
    30         //printf("%d %d
    ",i,j);
    31         for(;cow[j].first<=gra[i].first&&j<=N;j++){
    32             st.insert(cow[j].second);
    33         }
    34         if(st.empty()||(*st.begin())>gra[i].second) continue;
    35         multiset<int>::iterator it=st.upper_bound(gra[i].second);it--;
    36         //printf("%d %d %d %d
    ",gra[i].first,gra[i].second,*it,it==st.end());
    37         st.erase(it);ans+=gra[i].first;num++;
    38     }
    39     if(num==N) printf("%lld
    ",ans);
    40     else printf("-1
    ");
    41     return 0;
    42 }
  • 相关阅读:
    SCM基础之SCM配置管理计划重要性
    SCM基础之合理设计配置库
    SCM英文术语
    中国歼20隐形战机首飞成功
    SCM基础之过程描述
    SCM基础之基线审核
    SCM基础之组织结构设计
    SCM基础之如何做到配置管理
    配置管理介绍
    软件配置管理的任务
  • 原文地址:https://www.cnblogs.com/Ressed/p/9648837.html
Copyright © 2011-2022 走看看