HDU 4864 task (Greedy)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4864


----------------------------------------------------------------------------------------------------------------------------------------------------------
Welcome to tianci Hut: http://user.qzone.qq.com/593830943/main
 
----------------------------------------------------------------------------------------------------------------------------------------------------------

Task Time 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 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

Authorfzu source2014 multi-university training contest 1 recommendwe have carefully selected several similar problems for you: 4871 4870 4869 4868 4867

The basic idea is greed:

For the value c = 500 * Xi + 2 * Yi, Yi has a maximum impact of 100*2 <500, so the sum of Xi is the greatest. You can first sort the time of machines and tasks from large to small. Start from the task of the maximum time, find all the machines that meet the task time requirements, and find the machine matching that meets the task level requirements at the lowest level. Search for machines that meet the requirements for tasks in turn.

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 (. X = B. x) return. y> B. y; return. x> B. x;} int main () {int n, m; int I, j; int C [N]; while (~ Scanf ("% d", & N, & M) {memset (C, 0, sizeof (c); for (I = 1; I <= N; I ++) {scanf ("% d", & Ma [I]. x, & Ma [I]. y) ;}for (I = 1; I <= m; I ++) {scanf ("% 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) {// search for all the machines that can complete the current task. C [ma [l]. y] ++; l ++;} For (j = TA [I]. y; j <= 100; j ++) {// find the IF (C [J]) {num ++; ans ++ = 500 * Ta [I]. X + 2 * Ta [I]. y; C [J] --; break ;}} printf ("% d % i64d \ n", num, ANS);} return 0 ;}


HDU 4864 task (Greedy)

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.