Ultraviolet A 10382 watering grass

Source: Internet
Author: User

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  ;} 

 

 

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.