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

HDU4864 Task

时间:2014-07-23 16:50:31      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   java   color   os   

Task

 

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1997 Accepted Submission(s): 517



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

 

题意:给n个机器和m个任务,机器和任务都有时间和等级,只能机器的等级和时间都大于这个任务机器才能完成这个任务(一台机器最多只能完成一个额任务),问最多能完成几个任务,任务相同输出最大的价值。

这题用贪心做,虽然想到了贪心但是贪心策略错了最后还是没能AC,因为任务的价值实际上就只是受时间的影响(2*100都不大于500,所以时间差1排序就不用看等级了),所以任务和机器都按时间从大到小排序,然后用任务区匹配机器,找出满足时间要求里等级最小的机器与任务匹配,这样做实际上都只遍历了一遍机器和一遍任务(遍历多次机器就超时了)。

 

#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL __int64
using namespace std;
const int MAXN=100010;
int vis[MAXN];
struct machine
{
    LL time,level;
}m[MAXN];
struct task
{
    LL time,level;
    LL d;
}t[MAXN];
bool cmp1(machine a,machine b)
{
    if(a.time==b.time)
        return a.level>b.level;
    return a.time>b.time;
}
bool cmp2(task a,task b)
{
    if(a.time==b.time)
        return a.level>b.level;
    return a.time>b.time;
}
int main()
{
    int n,k,i,j,p;
    while(scanf("%d%d",&n,&k)==2)
    {
        for(i=0;i<n;i++)
            scanf("%I64d%I64d",&m[i].time,&m[i].level);
        sort(m,m+n,cmp1);
        for(i=0;i<k;i++)
        {
            scanf("%I64d%I64d",&t[i].time,&t[i].level);
            t[i].d=500*t[i].time+2*t[i].level;
        }
        sort(t,t+k,cmp2);
        int cnt=0;
        LL ans=0;
        memset(vis,0,sizeof(vis));
        for(i=0,j=0;i<k;i++)
        {
            while(m[j].time>=t[i].time&&j<n)
            {
                vis[m[j].level]++;  //机器可能具有相同的等级
                j++;
            }
            for(p=t[i].level;p<=100;p++)
            {
                if(vis[p])
                {
                    cnt++;
                    ans+=t[i].d;
                    vis[p]--;
                    break;
                }
            }
        }
        printf("%d %I64d\n",cnt,ans);
    }
    return 0;
}

HDU4864 Task,布布扣,bubuko.com

HDU4864 Task

标签:des   style   blog   java   color   os   

原文地址:http://www.cnblogs.com/tjwpmk3/p/3863360.html

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