Hdu 4869 Task (greedy)

Source: Internet
Author: User

Topic Link: hdu 4869 Task

The main topic: There are N machines, M task. Every machine and task has XI and Yi. Requirements of the XI of the machine. Yi is more than equal to the task of Xi and Yi talent to run the task.

Each machine can only run one task per day. The number of tasks requested is as large as possible, and the amount is as high as possible.

The amount of each task is completedx i ? 500 + y i ? 2

Problem-solving ideas: Greedy, mach[i][j] indicates the number of machines rated I, Time is J, Task[i][j] indicates the number of machines rated I, Time J.

Each time a priority is lowered I, as the corresponding level is reduced by 100, the corresponding amount of the cost will not be reduced by more than 500 (that is, time reduced by 1).
Each time mach[i][j] to add mach[i][j+1], which is not used on the machine. TMP records the number of machines at the current J level that are greater than I.

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace STD;typedef__int64 ll;Const intMaxt =1440;Const intMaxd = -;intN, M;intMach[maxd+Ten][maxt+Ten], task[maxd+Ten][maxt+Ten];voidInit () {intA, B;memset(Mach,0,sizeof(Mach));memset(Task,0,sizeof(Task)); for(inti =0; i < N; i++) {scanf("%d%d", &a, &b);    mach[b][a]++; }/* for (int i = maxd; I >= 0, i--) for (int j = maxt; J >= 0; j--) mach[i][j] = Mach[i][j]            + Mach[i+1][j] + mach[i][j+1]-mach[i+1][j+1]; */     for(inti =0; i < M; i++) {scanf("%d%d", &a, &b);    task[b][a]++; }}voidSolve () {ll ans =0;intCNT =0; for(intj = Maxt; J >=0; j--) {intTMP =0; for(inti = Maxd; I >=0; i--) {Mach[i][j] + = mach[i][j+1]; TMP + = Mach[i][j];intk = min (tmp, task[i][j]); Ans + = (ll) k * (2LL * i +500LL * j);            TMP-= k; CNT + = k; for(intx = i; x <= maxd; X + +) {intp = min (mach[x][j], k);                K-= p; MACH[X][J]-= p;if(k = =0) Break; }        }    }printf("%d%i64d\n", CNT, ans);}intMain () { while(scanf("%d%d", &n, &m) = =2&& N + M) {init ();    Solve (); }return 0;}

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Hdu 4869 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.