Uvalive 4254 Processor

Source: Internet
Author: User

It is easy to think of two points, the problem is with the feasibility of judging a solution. Greedy, up to 20,000 points in time, you can simulate each point in time, sort events by start time,

Each time you prioritize a task that has already started and the earliest end time, if a task does not end before deadline, it is not feasible to indicate the current solution.

The upper bounds of R are not well estimated, (far from the sum, but larger than MAXW, because the task overlaps in time), slightly larger.

#include <bits/stdc++.h>using namespacestd;Const intMAXN = 1e4+5;structjob{intr,d,w; BOOL operator< (ConstJob &rh)Const {        returnD > Rh.d;//return r < RH.R | | (r = = RH.R && d < Rh.d);    }    voidIn () {scanf ("%d%d%d",&r,&d,&W); }}J[MAXN];BOOLcmpConstJob&a,ConstJOB&AMP;B) {returnA.R <B.R;}Const intMaxd =2e4;intN;BOOLOkintm) {Priority_queue<Job>Q;  for(inti =2, j =0; I <= Maxd; i++){         while(J < n && J[J].R < i) Q.push (j[j++]); intW =m;  while(w>0&&q.size ()) {Job cur=q.top (); Q.pop (); if(CUR.W <=W) {W-=CUR.W; }Else {                if(CUR.D <= i)return false; CUR.W-=W;                Q.push (cur); W=0; }        }        if(j = = n && q.empty ())return true; }    return false;}intMain () {//freopen ("In.txt", "R", stdin);    intT scanf"%d",&T);  while(t--) {scanf ("%d",&N);  for(inti =0; I < n; i++) J[i].        In (); Sort (J,j+n,cmp); intL =1, R =1e4,m;  for(; L<r; Ok (M)? r=m:l=m+1) M = (l+r) >>1; printf ("%d\n", L); }    return 0;}

Uvalive 4254 Processor

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.