There are n tasks, each task has ri,di,wi, and the [Ri,di] representing the task represents the time interval in which the task can be done, while WI represents the workload of the task; now there is a processor, if it is executed at a speed of s, then the time required to complete the I task is wi/s; Required to calculate the minimum value of the maximum speed during processor execution
The idea is very simple two points, but how to simulate is difficult, can simulate the processor every second of the work, for every second, with priority queue to store the current time under the task can be processed, preferential treatment of D small, if finished, then deal with the next task, if not finished, time plus one.
#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <iostream > #include <algorithm> #include <vector> #include <map> #include <queue> #include <stack& Gt #include <string> #include <map> #include <set> #define EPS 1e-6 #define LL Long long using namespace std; const int MAXN = 10000 + 100;const int INF = 0x3f3f3f3f;int n;struct Task {int R, D, W;bool operator < (const TASK& ; A) const {return d > A.D;}}; BOOL CMP (Task A, task B) {return A.R < B.R;} Task tasks[maxn];void init () {cin >> n;for (int i = 0; i < n; i++) {cin >> TASKS[I].R >> tasks[i].d &G T;> TASKS[I].W;} Sort (tasks, tasks+n, CMP);} BOOL Check (int speed) {priority_queue<task> Q;int today = 1, pcnt = 0;while (pcnt < n | |!q.empty ()) {while (pcnt < ; n && tasks[pcnt].r = Now) Q.push (tasks[pcnt++]); int. = speed; Workload per unit time while (!q.empty () && work) {Task tmp = Q.top (); Q.pop (); if (Work > TMP.W) Work-= Tmp.w;else if (work = = TMP.W) {if (!q.empty () && q.top (). D = = now+1) return FAL se;work = 0;} else {if (TMP.D = = now+1) return FALSE;TMP.W-= work, work = 0;q.push (TMP);}} now++;} return true;} void Solve () {int left = 1, right = Inf;while (left < right) {int mid = left + (right-left)/2;if (check (mid)) right = Mid;else left = mid + 1;} cout << right << Endl;} int main () {//freopen ("Input.txt", "R", stdin); int T; CIN >> T;while (t--) {init (); Solve ();} return 0;}
Uvalive 4254 Processor Processor (two-part simulation + greedy)