14多校第一场 1004(HDU4864)Task

1004(HDU4864) Task

题目描述:

Today the company has m tasks to complete. The ith task need ximinutes to complete. Meanwhile, this task has a difficulty level yi. Themachine whose level below this task’s level yi cannot complete this task. Ifthe company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has amaximum working time and a level. If the time for the task is more than themaximum working time of the machine, the machine can not complete this task.Each machine can only complete a task one day. Each task can only be completedby one machine.
The company hopes to maximize the number of thetasks which they can complete today. If there are multiple solutions, theyhopes to make the money maximum.

 

大意:

 

工厂有m任务和n个机器,每个任务有它所需的时间和等级,机器同样如此,每个机器只能做一件任务,完成每件任务的得到 500*时间+200*等级  这么多钱,问最多能收获多少钱?

 

官方题解:

 

基本思想是贪心。

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

 

代码:

复杂度是 nlogn的,利用STL

/**

吉林大学
Jilin U

Statement:  以下代码完全由作者个人完成,不存在抄袭、套用。
Author:     sinianluoye (JLU_LiChuang)
Date:       2014-07-22
Usage:      多校第一场

**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>

#define ll long long
#define eps 1e-8
#define ms(x,y) (memset(x,y,sizeof(x)))
#define fr(i,x,y) for(int i=x;i<=y;i++)

using namespace std;

struct task
{
    int t,w;
};

bool cmp(task a,task b)
{
    if(a.t!=b.t)return a.t>b.t;
    else return a.w>b.w;
}

const int maxn=1e5+10;

task tas[maxn],mac[maxn];

int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        ms(used,0);
        for(int i=1;i<=n;i++)
            scanf("%d%d",&mac[i].t,&mac[i].w);
        for(int i=1;i<=m;i++)
            scanf("%d%d",&tas[i].t,&tas[i].w);
        sort(mac+1,mac+n+1,cmp);
        sort(tas+1,tas+m+1,cmp);

        ll num=0,ans=0;
        multiset<int>s;
        for(int i=1,j=1;i<=m;i++)
         {
             while(j<=n&&mac[j].t>=tas[i].t)
                 s.insert(mac[j++].w);
             multiset<int>::iterator p=s.lower_bound(tas[i].w);
             if(p!=s.end())
             {
                num++;
                ans+=500*tas[i].t+2*tas[i].w;
                s.erase(p);
             }
         }
         cout<<num<<' '<<ans<<endl;
    }
    return 0;
}

/*************copyright by sinianluoye (JLU_LiChuang)***********/



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值