码迷,mamicode.com
首页 > 其他好文 > 详细

HDU--4486 Task(贪心)

时间:2018-12-06 01:35:19      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:lan   php   bool   tar   std   ++   size   题目   span   

题目链接  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;
}

 

HDU--4486 Task(贪心)

标签:lan   php   bool   tar   std   ++   size   题目   span   

原文地址:https://www.cnblogs.com/DyLoder/p/10074333.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!