HDU--4486 Task(贪心)
题目链接 4486 Task
按照时间从大到小排序 然后枚举所有的y值 用一个数组存储 符合要求就算上
#include<bits/stdc++.h> using namespace std; #define LL long long #define maxn 200001 struct ac{ LL x,y; }a[maxn],b[maxn]; LL c[maxn]; bool cmp(ac q,ac w){ if(q.x==w.x) return q.y>w.y; return q.x>w.x; } int main(){ LL n,m; while(cin>>n>>m&&n&&m){ for(LL j=1;j<=n;j++){ scanf("%lld%lld",&a[j].x,&a[j].y); } for(LL j=1;j<=m;j++){ scanf("%lld%lld",&b[j].x,&b[j].y); } sort(a+1,a+1+n,cmp); sort(b+1,b+1+m,cmp); LL l=1; LL ans=0,sum=0; memset(c,0,sizeof(c)); for(LL j=1;j<=m;j++){ while(l<=n&&a[l].x>=b[j].x){ c[a[l].y]++; l++; } for(LL k=b[j].y;k<=100;k++){ if(c[k]){ c[k]--; sum++; ans+=1LL*(1LL*500*b[j].x+1LL*2*b[j].y); break; } } } cout<<sum<<" "<<ans<<endl; } return 0; }