Uva_10382
Whether the sprinkler can cover the lawn depends only on whether the blue area of each circle in the figure can cover the lawn. In this way, the problem is transformed into several lines, calculates the minimum number of line segments required to overwrite a specified range.
# Include <stdio. h> # Include < String . H> # Include <Math. h> # Include <Algorithm> # Define Maxn 10010 Const Double EPS = 1E- 10 ; Int N, m; Double L, W; Struct SEG { Double X, Y; Bool Operator <( Const SEG & T) Const { Return X <T. X ;}} seg [maxn]; Int DCMP ( Double X ){ Return (X> EPS)-(x <- EPS );} Double Sqr ( Double X ){ Return X * X ;} Void Input () {m = 0 ; For ( Int I = 0 ; I <n; I ++ ){ Double P, R; scanf ( " % Lf " , & P ,& R ); If (DCMP ( 2 * R-W) <= 0 ) Continue ; Double L = SQRT (sqr (R)-sqr (w * 0.5 ); Seg [M]. x = P-l, SEG [M]. Y = P + L, ++ M;} STD: Sort (SEG, SEG + M );} Int Process (){ Int CNT = 0 ; Double X = 0 , Y = 0 ; For ( Int I = 0 ; I <m; I ++ ){ If (DCMP (SEG [I]. X-x)> 0 ){ If (DCMP (SEG [I]. x-y)> 0 ) Return - 1 ; ++ CNT, x =Y; If (DCMP (X-l)> = 0 ) Return CNT;} y = STD: max (Y, SEG [I]. Y );} If (DCMP (Y-l) < 0 ) Return - 1 ; Return CNT + 1 ;} Int Main (){ While (Scanf ( " % D % lf " , & N, & L, & W) = 3 ) {Input (); printf ( " % D \ n " , Process ());} Return 0 ;}