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): 13880    Accepted Submission(s): 3420


    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

    题意:有n台机器,m个任务,每台机器和每个任务都有最大工作时间和工作等级,只有机器的最大工作时间和工作等级都大于任务的时间和等级时,任务才能被完成,每个任务有一个计分标准

    500*任务时间+2*任务等级;一台机器一天只能完成一个任务,问完成任务能获得的最大分数为多少

    题解:

    1、所有机器和任务都按时间从大到小排,时间相同再按水平从大到小排。

    2、从第一个任务开始,记录所有满足该任务等级的机器,然后从中选一个等级最小的去完成任务,(先加入的机器在时间上肯定能满足后面的任务

    3、接着下一个任务,加入能满足该任务的机器,选一个水平最小的,依次处理即可。

    注意:多组输入,数据类型:long long;

    #include<iostream>
    #include<algorithm>
    #include<string>
    #include<string.h>
    using namespace std;
    typedef long long ll;
    struct node
    {
        int t;
        int r;
    }m[100005], t[100005];
    int vis[100005];
    bool cmp(node a, node b)
    {
        if (a.t != b.t)
            return a.t > b.t;
        else
            return a.r > b.r;
    }
    int main()
    {
        int n, f;
        while (cin >> n >> f) 
        {
            for (int i = 0; i < n; i++)
                cin >> m[i].t >> m[i].r;
            for (int i = 0; i < f; i++)
                cin >> t[i].t >> t[i].r;
            sort(m, m + n, cmp);
            sort(t, t + f, cmp);
            int j = 0, cnt = 0;
            ll sum = 0;
            memset(vis, 0, sizeof(vis));
            for (int i = 0; i < f; i++)//遍历任务
            {
                while (j < n&&m[j].t >= t[i].t)//记录所有能完成第i个任务的机器等级
                {
                    vis[m[j].r]++;
                    j++;
                }
                for (int k = t[i].r; k <= 100; k++)
                {
                    if (vis[k])//如果有机器可以完成这个等级的任务
                    {
                        vis[k]--;
                        cnt++;
                        sum = sum + 500 * t[i].t + 2 * t[i].r;
                        break;
                    }
                }
            }
            cout << cnt << ' ' << sum << endl;
        }
        return 0;
    }
    
    
  • 相关阅读:
    OnEraseBkgnd、OnPaint与画面重绘
    .编译ADO类DLL时报错的解决方案
    VC列表框样式
    Codeforces 131D. Subway 寻找环树的最短路径
    Codeforces 103B. Cthulhu 寻找奈亚子
    Codeforces 246D. Colorful Graph
    Codeforces 278C. Learning Languages 图的遍历
    Codeforces 217A. Ice Skating 搜索
    Codeforces 107A. Dorm Water Supply 搜图
    Codeforces 263 D. Cycle in Graph 环
  • 原文地址:https://www.cnblogs.com/-citywall123/p/11214005.html
Copyright © 2011-2022 走看看