Hdu 4864 Task (greedy AH)

Source: Internet
Author: User

Topic Links:

pid=4864 ">http://acm.hdu.edu.cn/showproblem.php?pid=4864



TaskTime limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 1346 Accepted Submission (s): 336

Problem Descriptiontoday The company have m tasks to complete. The ith task need XI minutes to complete. Meanwhile, this task have 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'll get (500*xi+2*yi) dollars.
The company has n machines. Each machine have a maximum working time and a level. If the time for the task was more than the maximum working time of the "machine", the machine can not be complete this task. Each machine can be only complete a task one day. Each task can is only being completed by one machine.
The company hopes to maximize the number of the tasks which they can complete today. If There is multiple solutions, they hopes to make the money maximum. Inputthe input contains several test cases.
The first line contains the 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 a integers XI (0<xi<1440), Yi (0=<yi<=100). Xi is the maximum time the Machi NE can work.yi is the level of the machine.
The following M lines each contains a integers XI (0<xi<1440), Yi (0=<yi<=100). Xi is the time we need to comple Te the Task.yi is the level of the task. Outputfor each test case, output integers, the maximum number of the tasks which the company can complete today and th E money they would get. Sample Input
1 2100 3100) 2100 1
Sample Output
1 50004

Authorfzu Source2014 multi-university Training Contest 1 recommendwe has carefully selected several similar problems for you:4871 4870 4869 4868 4867

basic idea is greedy :

c=500*xi+2*yi yi 100*2<500, so it's asking. xi Total maximum.

The ability to first machine and task time sort from big to small . Start with the maximum time task. Find all the machines that meet the task time requirements. Find the machine match with the lowest level and meet the task level requirements. Search the task in turn for the machine that meets the requirements.

The code is as follows:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int N = 100017;struct work{int x, y;} Ma[n],ta[n];bool CMP (work A, work B) {if (a.x = = b.x) return a.y > B.y;return a.x > b.x;} int main () {int n, m;int i, J;int c[n];while (~scanf ("%d%d", &n,&m)) {memset (c,0,sizeof (c)); for (i = 1; I <= n; i++) {scanf ("%d%d", &MA[I].X,&MA[I].Y);} for (i = 1; I <= m; i++) {scanf ("%d%d", &TA[I].X,&TA[I].Y);}  Sort (ma+1,ma+n+1,cmp), sort (ta+1,ta+m+1,cmp), int l = 1;__int64 ans = 0;int num = 0;for (i = 1; I <= m; i++) {while (L <= n&&ma[l].x >= ta[i].x) {//Find all the machines that can complete the current task c[ma[l].y]++;l++;} for (j = ta[i].y; J <= + j + +) {//Search for all machines that can complete the current task in the lowest rank if (C[j]) {num++;ans+=500*ta[i].x+2*ta[i].y;c[j]--;break;}}} printf ("%d%i64d\n", Num,ans);} return 0;}


Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Hdu 4864 Task (greedy AH)

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.