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

HDU 4864(多校)1004 Task

时间:2014-07-22 23:57:27      阅读:601      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   

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
 

Source
 
我的渣代码就是过不了,看了大神 点击打开链接 的,开始觉得有BUG,后来想了想
这种方法真好,值得我去学习=-=
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
int n,m;
int h[maxn];
struct node{
    int x,y;
}e[maxn],f[maxn];
int cmp(node l1,node l2)
{
     if(l1.x==l2.x)
         return l1.y>l2.y;
     return l1.x>l2.x;
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        memset(h,0,sizeof(h));
        for(int i=0;i<n;i++)
            scanf("%d%d",&e[i].x,&e[i].y);
        for(int i=0;i<m;i++)
            scanf("%d%d",&f[i].x,&f[i].y);
        sort(e,e+n,cmp);
        sort(f,f+m,cmp);
        int num=0,j=0;
        long long ans=0;
        for(int i=0;i<m;i++)
        {
            while(j<n&&e[j].x>=f[i].x)//由于对e,f,都排了序所以找出大于f[i].x所有的e[j],将e[j].y储存起来;
            {
                h[e[j].y]++;
                j++;
            }
            for(int k=f[i].y;k<=100;k++)//从找到的e[j].y中选择最小的
            {
                if(h[k])//判断是否存在
                {
                    h[k]--;
                    num++;
                    ans+=f[i].x*500+f[i].y*2;
                    break;
                }
            }
        }
        printf("%d %I64d\n",num,ans);
    }
    return 0;
}


HDU 4864(多校)1004 Task,布布扣,bubuko.com

HDU 4864(多校)1004 Task

标签:des   style   blog   http   color   os   

原文地址:http://blog.csdn.net/u013582254/article/details/38050931

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