HDU 4864 Task (Greedy)

Source: Internet
Author: User

HDU 4864 Task (Greedy)
HDU 4864 Task

Question Link

Some machines and tasks all have time and level. The condition for a machine to perform a task is that the time level is greater than or equal to the task, and a task can only be performed by one machine, now we want to maximize the task and ensure as much money as possible.

Idea: greedy. For each task, priority is given to matching when the time is large. If the time is the same, priority is given to matching when the level is large. Because time accounts for a large amount of time, when the time is 1, it will be 500 more, the maximum level is 200. When matching, try to use a match with a lower level, and the time can be used as long as it is greater than it, because it is time-based, so if the time can match a larger, other matches can certainly be matched, so the priority must be greater, so as long as the level is as small as possible.

Code:

#include 
 
  #include 
  
   #include 
   
    using namespace std;typedef __int64 ll;const int N = 1444;const int M = 105;int n, m;ll mac[N][M], task[N][M], used[N];int main() {    while (~scanf("%d%d", &n, &m)) {int x, y;memset(mac, 0, sizeof(mac));memset(task, 0, sizeof(task));memset(used, 0, sizeof(used));for (int i = 0; i < n; i++) {    scanf("%d%d", &x, &y);    mac[x][y]++;}for (int i = 0; i < m; i++) {    scanf("%d%d", &x, &y);    task[x][y]++;}for (int i = 0; i <= 100; i++) {    for (int j = 1439; j > 0; j--) {mac[j][i] += mac[j + 1][i];    }}ll num = 0;ll ans = 0;for (ll i = 1439; i > 0; i--) {    for (ll j = 100; j >= 0; j--) {if (!task[i][j]) continue;for (ll k = j; k <= 100; k++) {    if (task[i][j] > mac[i][k] - used[k]) {num += mac[i][k] - used[k];ans += (mac[i][k] - used[k]) * (i * 500 + j * 2);task[i][j] -= (mac[i][k] - used[k]);used[k] = mac[i][k];    }    else {num += task[i][j];ans += task[i][j] * (i * 500 + j * 2);used[k] += task[i][j];task[i][j] = 0;break;    }}    }}printf("%I64d %I64d\n", num, 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.