From 4471340212a3c70289391667bf47eb08886851c2 Mon Sep 17 00:00:00 2001 From: xande1505 Date: Thu, 8 Jun 2017 14:53:12 -0300 Subject: [PATCH] Square root fixed In some cases the range was -NaN, we need to fix the range --- UVa 10382 - Watering Grass.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/UVa 10382 - Watering Grass.cpp b/UVa 10382 - Watering Grass.cpp index afb27d4..e3f436c 100644 --- a/UVa 10382 - Watering Grass.cpp +++ b/UVa 10382 - Watering Grass.cpp @@ -26,7 +26,14 @@ int main() cin >> pos >> radius; // Calculate this circle's effective interval [L, R]. // Then this problem is identical to 10020 - Minimal coverage. - double range = sqrt(radius * radius - (w / 2.0) * (w / 2.0)); + double circle = radius * radius - (w / 2.0) * (w / 2.0); + double range; + + if( circle >= 0.0 ) + range = sqrt( circle ); + else + range = 0.0; + circles[0].L = pos - range; circles[0].R = pos + range; circles.push_back(circles[0]); @@ -63,4 +70,4 @@ int main() cout << nSprinklers << endl; } return 0; -} \ No newline at end of file +}