HDU 4864 贪心

有n个机器,m个任务,每个任务只能交给一个机器做,每个机器只能做一个任务,任务需要同时满足时间<=x, 等级>=y


基本思想是贪心。

对于价值c=500*xi+2*yiyi最大影响100*2<500,所以就是求xi总和最大。可以先对机器和任务的时间从大到小排序。从最大时间的任务开始,找出满足任务时间要求的所有机器,从中找出等级最低且满足任务等级要求的机器匹配。依次对任务寻找满足要求的机器。


#include "stdio.h"
#include "string.h"
#include "math.h"
#include "algorithm"
using namespace std;

struct node
{
    int x,y;
}a[100010],b[100010];

bool cmp(node a,node b)
{
    if (a.x==b.x) return a.y>b.y;
    else return a.x>b.x;
}
int hash[101];
int main()
{
    int n,m,i,j,ans1,l;
    __int64 ans2;

    while (scanf("%d%d",&n,&m)!=EOF)
    {
        for (i=0;i<n;i++)
            scanf("%d%d",&a[i].x,&a[i].y);
        for (i=0;i<m;i++)
            scanf("%d%d",&b[i].x,&b[i].y);
        sort(a,a+n,cmp);
        sort(b,b+m,cmp);

        memset(hash,0,sizeof(hash));

        ans1=ans2=0;
        j=0;
        for (i=0;i<m;i++)
        {
            while(j<n && a[j].x>=b[i].x)
                hash[a[j++].y]++;
            for (l=b[i].y;l<=100;l++)
                if (hash[l]!=0)
                {
                    hash[l]--;
                    ans1++;
                    ans2+=500*b[i].x+2*b[i].y;
                    break;
                }
        }
        printf("%d %I64d\n",ans1,ans2);

    }
    return 0;


}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值