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)***********/



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章