HDU covers an area of 1225 square meters

Source: Internet
Author: User

Hdu_1225

To expand the sum of the rectangle that covers K times, it is uva_11983. When we feel that we use the line segment tree to process the rectangle, we first need to mark which intervals are covered, and then we need to use the idea similar to DP, cover [I] [J] indicates that the node I on the online segment tree is within the specified range and covers the total length of the Line Segment for J times, at the same time, cover [I] [k] indicates the total length of a line segment that overwrites K times and exceeds K times, then, the status of cover [I] [J] is updated based on the status of the left and right sons.

# Include <stdio. h> # Include < String . H> # Include <Stdlib. h> # Include <Math. h> # Define Maxd 2010 # Define Zero 1e-8 Int N, m, CNT [4 * Maxd], K = 2  ;  Double Ty [maxd], cover [ 4 * Maxd] [ 3  ];  Struct  SEG {  Double  X, Y1, Y2;  Int  Col;} seg [maxd];  Int Cmpy ( Const  Void * _ P, Const   Void * _ Q ){  Double * P = ( Double *) _ P, * q = ( Double * ) _ Q;  Return * P <* Q? - 1 : 1  ;}  Int CMPS ( Const  Void * _ P, Const   Void * _ Q) {seg * P = (SEG *) _ p, * q = (SEG * ) _ Q;  Return P-> x <q-> X? - 1 : 1  ;}  Int DCMP ( Double  X ){  Return FABS (x) <zero? 0 : (X < 0 ? - 1 : 1  );}  Void Build ( Int Cur, Int X, Int  Y ){  Int Mid = (x + y)> 1 , Ls = cur < 1 , RS = (cur < 1 ) |1  ; Memset (cover [cur],  0 , Sizeof  (Cover [cur]); cover [cur] [  0 ] = Ty [Y + 1 ]- Ty [X]; CNT [cur] = 0  ;  If (X = Y)  Return  ; Build (LS, X, mid); Build (RS, mid +1  , Y );}  Void  Init (){  Int  I, J, K;  Double  X1, x2, Y1, Y2; scanf (  "  % D  " ,& N );  For (I = 0 ; I <n; I ++ ) {J = I <1 , K = (I < 1 ) | 1  ; Scanf (  "  % Lf  " , & X1, & Y1, & X2 ,& Y2); seg [J]. x = X1, SEG [K]. x = X2; seg [J]. Y1 = Seg [K]. Y1 = Y1, SEG [J]. y2 = seg [K]. y2 = Y2; seg [J]. Col = 1 , SEG [K]. Col =- 1 ; Ty [J] = Y1, Ty [k] = Y2;} qsort (TY, n < 1 , Sizeof (TY [ 0  ]), Cmpy); m = (N < 1 )- 1  ; Build (  1 , 0 , M- 1  );}  Void Update (Int Cur, Int X, Int  Y ){  Int Ls = cur < 1 , RS = (cur < 1 ) | 1  ; Memset (cover [cur],  0 , Sizeof  (Cover [cur]);  If (CNT [cur]> = K) cover [cur] [k] = Ty [Y + 1 ]- Ty [x];  Else   If (X = Y) cover [cur] [CNT [cur] = Ty [Y + 1 ]- Ty [x];  Else  {  Int  I;  For (I = CNT [cur]; I <= K; I ++ ) Cover [cur] [I] + = Cover [ls] [I-CNT [cur] + cover [RS] [I-CNT [cur];  For (I = k-CNT [cur] + 1 ; I <= K; I ++ ) Cover [cur] [k] + = Cover [ls] [I] + Cover [RS] [I] ;}}  Void Refresh ( Int Cur, Int X, Int Y, Int S, Int T, Int  C ){ Int Mid = (x + y)> 1 , Ls = cur < 1 , RS = (cur < 1 ) | 1  ;  If (X> = S & Y <= T) {CNT [cur] + = C; Update (cur, x, y );  Return  ;}  If (Mid> =S) Refresh (LS, X, mid, S, T, C );  If (Mid + 1 <= T) Refresh (RS, mid + 1  , Y, S, T, C); Update (cur, x, y );}  Int BS ( Double  X ){  Int Min = 0 , Max = m + 1  , Mid;  For (;) {Mid = (Min + max)> 1  ;  If (Mid = Min)  Break  ;  If (DCMP (TY [Mid]-x) <= 0  ) Min = Mid;  Else  Max = Mid ;} Return  Mid ;}  Void  Solve (){  Int  I, J, K;  Double Ans = 0  ; Qsort (SEG, n < 1 , Sizeof (SEG [ 0  ]), CMPs); seg [n < 1 ]. X = seg [(n <1 )- 1  ]. X;  For (I = 0 ; I <(n < 1 ); I ++ ) {J = BS (SEG [I]. Y1), k = BS (SEG [I]. Y2 );  If (J < K) Refresh (  1 , 0 , M- 1 , J, k-1  , SEG [I]. col); ans + = Cover [ 1 ] [K] * (SEG [I + 1 ]. X- SEG [I]. X);} printf (  "  %. 2f \ n  "  , ANS );}  Int  Main (){  Int  T; scanf (  "  % D  " ,& T );  While (T -- ) {Init (); solve ();}  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.