hdu 4864 Task

来源:互联网 发布:淘宝网店名字能改吗 编辑:程序博客网 时间:2024/06/06 09:42


http://acm.hdu.edu.cn/showproblem.php?pid=4864

Task

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


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 2100 3100 2100 1
 

Sample Output
1 50004

题目大意:有机器有任务,每个机器都有最大运行时间和可接任务的最大难度,每个任务都有所需时间和难度给n个机器m个任务每个机器只能选一个任务,求最多能选多少个任务,并求出∑(500*xi+2*yi) dollars,如果有多种解求出钱数最多的解法,输出选择任务的数目和总钱数。

分析:机器和任务按照时间降序排列 ,让任务去找机器   在机器的时间符合要求的前提下找到一个级别最小的能满足任务难度要求的机器来完成这项任务  按时间从大到小找完所有机器。

//http://acm.hdu.edu.cn/showproblem.php?pid=4864#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;struct node{    int x,y;//x时间,y等级; } s1[100005],s2[100005];int cmp(node a,node b){    if(a.x == b.x)        return a.y>b.y;    return a.x>b.x;}int main()//不同的机器可以同时进行相同的任务;{    int n,m,i,j,cnt;    long long sum;    while(~scanf("%d%d",&n,&m))    {        for(i=0;i<n;i++)            scanf("%d%d",&s1[i].x,&s1[i].y);        for(i=0;i<m;i++)            scanf("%d%d",&s2[i].x,&s2[i].y);        sort(s1,s1+n,cmp);        sort(s2,s2+m,cmp);        cnt=sum=0;        int c[105]={0};//s1[]机器;s2[]任务;        for(i=0,j=0;i<m;i++){                     while(j<n&&s1[j].x>=s2[i].x){//j扫描机器,机器时间能满足任务时间并且机器没扫描完时;            //当当前的机器能满足现在的任务时间时,一定能满足下一个任务的时间(排序)。 //下一次接着上一次的位置扫,这样不会将已经选过的机器重复选用。                 c[s1[j].y]++;//该机器等级对应的数字++;                 j++;            }//直到扫完所有机器或机器运行时间已经不能满足任务所需时间;            //扫完后将从上一次记录的地方开始所有满足当前任务的机器都标记;             for(int k=s2[i].y;k<=100;k++)                if(c[k]){//找到一个最小能满足任务条件的机器进行当前的任务 ;                    c[k]--;                    sum+=(s2[i].x*500+s2[i].y*2);                     cnt++;                    break;                }        }        printf("%d %lld\n",cnt,sum);    }}







原创粉丝点击