## SPOJ 8670. THE MAX LINES

import Data.List import Text.Printf import Control.Monad import qualified Data.ByteString.Char8 as BS readN::BS.ByteString -> Integer readN x = case BS.readInteger x of Nothing -> 0 Just ( t , _ ) -> t main = do n <- liftM readN ( BS.getLine ) let fun x k | x > k = return () | otherwise = do m <- liftM readN ( BS.getLine ) printf "Case %d: %.2f\n" x ( fromIntegral ( 4*m^2 ) + ( 0.25::Double ) ) fun (x+1) k return () fun 1 n

SPOJ 8670. THE MAX LINES is easy one. From problem’s figure you can see [ from the property of semi circle ] so we can also write . We got quadratic in AC . Our variable point is A so lets say AC = x then we have . Differentiating s with respect to x we have and . Clearly we have maximum at . Equating it to zero we get .Putting this value in we have . Here is one more analysis.

PS. Some times i get bizarre problem with sourcecode tag. It was not rendering the code in below so i had to put the code first and analysis second :P.

Advertisements

thank you, This is very helpful.. 🙂

Comment by leli | September 26, 2011 |

i try solving this with c++, but got wrong answer 😦

Comment by eve | October 8, 2011 |