HDU 4864 task

Source: Internet
Author: User

Link: HDU 4864 task

Task Time Limit: 4000/2000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 843 accepted submission (s): 185


Problem descriptiontoday 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.
Inputthe 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.
Outputfor 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
 
Source2014 multi-university training contest 1
Recommendwe have carefully selected several similar problems for you: 4871 4870 4869 4868 4867

Question:

There are n machines and M tasks. Each machine can complete one task at most. For each machine, there is a maximum run time XI and level Yi. For each task, there is also a run time XJ and level YJ. Only when xi> = XJ and Yi> = YJ, machine I can complete task J and get 500 * XJ + 2 * YJ money. Ask how many tasks can be completed, and when there are multiple situations, output the most money.

Analysis:

When I did not make such a question during the competition, I could only say that I am too watery. I learned the basic idea of greed from the beginning. That is, first sort the tasks and machines in descending order (first time, time is the same and then by difficulty), and then use greedy solutions. At that time, the brain hole was too big. First, select a machine and select the task with the maximum profit that the machine can accomplish. However, when selecting the next machine, I forgot to consider the tasks ignored by the previous machine, in the end, this problem occurs when the infinite Wa is caused. The online question is to select a task and then select the appropriate minimum machine. I modified my code a little according to the question and AC it. In fact, it is the same as the idea of selecting a machine first. Alas, it's too stupid to do it.

Code:

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;#define maxn 100010struct node{    int tm, dif;}MCH[maxn], TSK[maxn];bool cmp(node a, node b){    if(a.tm==b.tm) return a.dif > b.dif;    return a.tm > b.tm;}int main(){    int n, m;    while(~scanf("%d%d", &n, &m))    {        for(int i = 1; i <= n; i++)            scanf("%d%d", &MCH[i].tm, &MCH[i].dif);        for(int i = 1; i <= m; i++)            scanf("%d%d", &TSK[i].tm, &TSK[i].dif);        sort(MCH+1, MCH+n+1, cmp);        sort(TSK+1, TSK+m+1, cmp);        int cnt = 0, c[102];        __int64 sum = 0;        memset(c, 0, sizeof(c));        for(int i = 1, j = 1; i <= m; i++)        {            while(j <= n && MCH[j].tm >= TSK[i].tm)            {                c[MCH[j].dif]++;                j++;            }            for(int k = TSK[i].dif; k <= 100; k++)            {                if(c[k])                {                    cnt++;                    c[k]--;                    sum += 500*TSK[i].tm+2*TSK[i].dif;                    break;                }            }        }        printf("%d %I64d\n", cnt, sum);    }    return 0;}




HDU 4864 task

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.