贪心:按照 a[i] .y 递减排序, 对每个牛取 所有物品的值 最大的
#include <bits/stdc++.h> using namespace std; const int N=2504; struct T{ int x,y; }a[N]; int n,m,cnt[N],val[N]; int ans=0; int cmp(T &a,T &b){ return a.x>b.x; } int find(int x){ int j,mx=0; for(int i=1;i<=m;i++){ if(cnt[i]&&a[x].x<=val[i]&&a[x].y>=val[i]&&mx<val[i]) mx=val[i],j=i; } if(mx) ans++,cnt[j]--; } signed main(){ cin>>n>>m; int i; for(i=1;i<=n;i++) cin>>a[i].x>>a[i].y; for(i=1;i<=m;i++)cin>>val[i]>>cnt[i]; sort(a+1,a+1+n,cmp); for(i=1;i<=n;i++)find(i); cout<<ans; }
标签:cnt,防晒,val,int,110,cmp,mx,acwing From: https://www.cnblogs.com/towboa/p/16935871.html