zoukankan      html  css  js  c++  java
  • hdu 4864 Task

    Task

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


    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
     

    题目:一家公司有m个任务须要完毕,每件任务有一个最少工作时间和一个任务难度,同一时候这家公司一共同拥有n台机器,每台相应一个最大工作时间和机器的等级,用这n台机器来完毕任务。每台机器每天能完毕一件任务----这件任务的须要的工作时间和任务难度分别要不超过机器的最长工作时间和机器的等级,每完毕一件任务,公司获得500*任务工作时间+2*任务等级的利润。给定这些任务和机器的具体情况,问最多能完毕多少件任务,利润是多少?(多种情况时输出最大利润)


    题解:比赛的时候,看了看过的队伍非常多,可是正确率却非常低,自己也没出这道题。比赛后看了题解才做出来的。

                题解的意思就是----每完毕一件任务,获得利润=500*t+2*w,这里w的范围是1-100,最大值W=200<500对于总体利润的影响非常小,所以对任务和时间均依照t递减排序,t同样依照w递减排序。然后从第一件任务開始遍历,找出全部可以解决这项任务的机器,并挑出工作时间最少,而且等级最低的那台来完毕这项任务,以此类推,直到全部任务都完毕。

             为什么要这样安排呢?任务排序之后,后边的任务的一部分是时间与当前任务时间同样,但任务等级低的,能过解决当前任务的机器比人可以完毕剩下的任务;另外一部分是时间比当前任务短,任务等级比当前任务高的,如果我挑走一台等级高机器,这台机器能完毕这两项任务,另外存在一台机器等级低的机器仅仅能完毕当前任务,如果我用等级高的那台来完毕当前任务的话,后来的任务就不能完毕了,所以我要选择等级低可是能完毕当前任务的那台机器;第三种情况,时间短,任务等级低的,可以完毕当前任务的那些机器必定能用来完毕这些任务。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    typedef __int64 LL;
    
    struct node{
      int x,y;
    }l[100010],r[100010];
    
    bool cmp(node a,node b)
    {
        if(a.x!=b.x)
            return a.x>b.x;
        return a.y>b.y;
    }
    int main()
    {
        int m,n;
        while(scanf("%d%d",&m,&n)!=EOF)
        {
            for(int i=0;i<m;i++)
                scanf("%d%d",&l[i].x,&l[i].y);
            for(int j=0;j<n;j++)
                scanf("%d%d",&r[j].x,&r[j].y);
    
            sort(l,l+m,cmp);
            sort(r,r+n,cmp);
    
            LL ans=0,num=0;
            int c[110],i,j;
            memset(c,0,sizeof(c));
    
            for(i=0,j=0;i<n;i++)
            {
                while(j<m&&l[j].x>=r[i].x)
                {
                    c[l[j].y]++;
                    j++;
                }
                for(int k=r[i].y;k<=100;k++)
                {
                    if(c[k])
                    {
                        c[k]--;
                        num++;
                        ans+=500*r[i].x+2*r[i].y;
                        break;
                    }
                }
            }
            printf("%I64d %I64d
    ",num,ans);
        }
        return 0;
    }




  • 相关阅读:
    DirectX9:基础篇 第五章 绘制流水线
    他山之石:可以攻玉
    C89:论内存分配问题
    C89:关键字
    MFC:开头篇 介绍
    DirectX9:先导篇 数学基础
    模仿轮播图效果
    text选中后displa出label内容
    ASP.NET页面之间传递值的几种方式
    jquery-delay(),queue()
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4483959.html
Copyright © 2011-2022 走看看