hdu4864Task(馋)

主题链接:

啊哈哈。点我

题目:

Task

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2512    Accepted Submission(s): 643


Problem Description
Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task’s level yi cannot complete this task. If the company completes this task, they will get (500*xi+2*yi) dollars.
The company has n machines. Each machine has a maximum working time and a level. If the time for the task is more than the maximum 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 completed by one machine.
The company hopes to maximize the number of the tasks which they can complete today. If there are multiple solutions, they hopes to make the money maximum.
 

Input
The input contains several test cases. 
The first line contains two integers N and M. N is the number of the machines.M is the number of tasks(1 < =N <= 100000,1<=M<=100000).
The following N lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the maximum time the machine can work.yi is the level of the machine.
The following M lines each contains two integers xi(0<xi<1440),yi(0=<yi<=100).xi is the time we need to complete the task.yi is the level of the task.
 

Output
For each test case, output two integers, the maximum number of the tasks which the company can complete today and the money they will get.
 

Sample Input
1 2 100 3 100 2 100 1
 

Sample Output
1 50004
 

Author
FZU
 

Source
 

Recommend
We have carefully selected several similar problems for you:  4881 4880 4879 4878 4877 

思路:

首先考虑获得的酬劳。。500*xi+2*yi,所以yi能够当做次要因素,主观因素是时间。所以对任务。和机器的时间大- >小,等级大->小排序。。

接下来就是枚举,将全部满足机器执行时间》=任务时间的增加数组。然后选满足完毕任务的最小等级的机器去完毕任务。

这种巧妙之处在于后面的加进来的任务必然能够被先前加进来的机所完毕。由于任务是按时间降序排列的。。

那样这道题就得到了完美的解决。。

代码为:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn=100000+10;
int level[100+10];
int n,m,sum;
__int64 ans;

struct P
{
    int xi,yi;
}machine[maxn],task[maxn];


bool cmp(P a,P b)
{
   if(a.xi==b.xi) return a.yi>b.yi;
   return a.xi>b.xi;
}

void read_data()
{
    for(int i=1;i<=n;i++)
        scanf("%d%d",&machine[i].xi,&machine[i].yi);
    for(int i=1;i<=m;i++)
        scanf("%d%d",&task[i].xi,&task[i].yi);
    sort(task+1,task+1+m,cmp);
    sort(machine+1,machine+1+n,cmp);
}

int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        ans=sum=0;
        read_data();
        memset(level,0,sizeof(level));
        for(int i=1,j=1;i<=m;i++)
        {
            while(j<=n&&machine[j].xi>=task[i].xi)
            {
                level[machine[j].yi]++;
                j++;
            }
            for(int k=task[i].yi;k<=100;k++)
            {
                if(level[k])
                {
                    level[k]--;
                    ans=ans+500*task[i].xi+2*task[i].yi;
                    sum++;
                    break;
                }
            }
        }
        printf("%d %I64d\n",sum,ans);
    }
    return 0;
}


版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-09-09 13:45  zfyouxi  阅读(195)  评论(0编辑  收藏  举报