La 4254 Processor

Source: Internet
Author: User

La_00004

Generally, the problem with the smallest maximum value can be solved by means of two points, which is no exception. After dividing the processor speed into two parts, the problem is converted into a given processing speed, asking whether the processor can solve these problems. A greedy idea is to try to do the earliest tasks that can be done at every moment, so that at least the result will not be worse. In this way, you can enumerate each unit time, and then find the one that can be done and the earliest end time, until this unit time is used up or no task can be done. If the task is not completed, it means that the processor cannot complete all tasks at the given processing speed.

In the process of searching for the earliest tasks that can be done at the end timeCodeThe line segment tree is used. However, according to the AC ranking, there should be simplerAlgorithmBut I didn't think of it for the moment.

# Include <stdio. h> # Include < String . H> # Include <Algorithm> # Include <Iostream> # Define Maxn 10010 # Define INF 0x3f3f3f Typedef  Long   Long  Ll;  Int N, D, tree [ 4 * Maxn], di [ 2 * Maxn], remain [maxn];  Struct  A {  Int  R, D, W;} A [maxn]; Bool CMP ( Const   Int X, Const   Int  Y ){  Int Tx = x> 0 ? A [X]. R: A [-X]. D, Ty = Y> 0 ? A [Y]. R: [- Y]. D;  Return TX < Ty ;}  Void  Input () {scanf ( "  % D  " ,& N );  For ( Int I = 1 ; I <= N; I ++ ) {Scanf (  "  % D  " , & A [I]. R, & A [I]. D ,& A [I]. W); di [  2 * I- 2 ] = I, di [2 * I- 1 ] =- I;} STD: Sort (Di, Di + 2 * N, CMP );  For (D = 1 ; D <n + 2 ; D <= 1  ); Memset (tree,  0 , Sizeof (Tree [ 0 ]) *2 * D); [  0 ]. D = INF ;}  Void Update ( Int  I ){  For (; I ^ 1 ; I >>= 1 ) Tree [I> 1 ] = A [tree [I]. d <A [tree [I ^ 1 ]. D? Tree [I]: Tree [I ^ 1  ];} Int Gett ( Int  I ){  Return I> 0 ? A [I]. R: [- I]. D ;}  Int Can ( Int  M ){  For ( Int I = 1 ; I <= N; I ++) remain [I] = A [I]. W; di [  2 * N] = di [2 * N- 1  ];  For ( Int I = 0 ; I < 2 * N; I ++ ){  If (Di [I]> 0 ) Tree [d + di [I] = di [I], update (D + Di [I]);  Else Tree [D-di [I] = 0 , Update (d-Di [I]); ll use = (LL) M * (gett (di [I + 1 ])- Gett (di [I]);  While  (Use ){  Int Id = tree [ 1  ];  If (ID = 0 ) Break  ;  If (Use> =Remain [ID]) {use -= Remain [ID], remain [ID] = 0  ; Tree [d + Id] = 0 , Update (D + ID );}  Else Remain [ID]-= use, use = 0  ;}}  For ( Int I = 1 ; I <= N; I ++) If (Remain [I])Return   0  ;  Return   1  ;}  Void  Process (){  Int Min = 0 , Max = 10000010  , Mid;  For  (;) {Mid = (Max-min )/ 2 +Min;  If (Mid = min) Break  ;  If (Can (MID) max = Mid;  Else Min = Mid;} STD: cout <Mid + 1 < STD: Endl ;}  Int  Main (){  Int  T; scanf ( "  % D  " ,& T );  While (T -- ) {Input (); process ();}  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.