Hdu4864Task (Greedy)

Source: Internet
Author: User

Hdu4864Task (Greedy)

Question link:

Ah, haha, click me.

Question:

Task Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 2512 Accepted Submission (s): 643


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 The following M lines each contains two integers xi (0 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

AuthorFZU
Source2014 Multi-University Training Contest 1
RecommendWe have carefully selected several similar problems for you: 4881 4880 4879 4878 4877

Ideas:

First, consider the reward .. 500 * xi + 2 * yi, So yi can be used as a secondary factor. Subjective factors are time. Therefore, the time for tasks and machines is large-> small, and the level is large-> small sorting ..

Next, we will enumerate and add all those that meet the running time of the machine = task time to the array, and then select the machine that meets the minimum level of the completed task to complete the task. This clever thing is that the subsequent tasks can be completed by the previously added machines. Because tasks are arranged in descending chronological order .. In this way, the question is perfectly solved ..

Code:

#include
   
    #include
    
     #include
     
      #includeusing namespace std;const int maxn=100000+10;int level[100+10];int n,m,sum;__int64 ans;struct P{    int xi,yi;}machine[maxn],task[maxn];bool cmp(P a,P b){   if(a.xi==b.xi) return a.yi>b.yi;   return a.xi>b.xi;}void read_data(){    for(int i=1;i<=n;i++)        scanf("%d%d",&machine[i].xi,&machine[i].yi);    for(int i=1;i<=m;i++)        scanf("%d%d",&task[i].xi,&task[i].yi);    sort(task+1,task+1+m,cmp);    sort(machine+1,machine+1+n,cmp);}int main(){    while(~scanf("%d%d",&n,&m))    {        ans=sum=0;        read_data();        memset(level,0,sizeof(level));        for(int i=1,j=1;i<=m;i++)        {            while(j<=n&&machine[j].xi>=task[i].xi)            {                level[machine[j].yi]++;                j++;            }            for(int k=task[i].yi;k<=100;k++)            {                if(level[k])                {                    level[k]--;                    ans=ans+500*task[i].xi+2*task[i].yi;                    sum++;                    break;                }            }        }        printf("%d %I64d\n",sum,ans);    }    return 0;}
     
    
   


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.