My Weblog

Blog about programming and math

SPOJ 4408. Build a Fence

SPOJ 4408. Build a Fence is related to area of circle . When we will fold the fence of length of L then it will circumference of semi circle [ Although i haven’t proved why for maximum , it should be circle ? Intuition again ] .  \pi *r = L . We have r = \frac L  \pi  . Area of semi circle is \frac {\pi * r * r} 2 = \frac {L^2} {2 * \pi} .

import Data.List
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Text.Printf

readD :: String -> Double
readD = read

main = do 
   n <- fmap readD getLine 
   when (n /=0 ) $ do 
	printf "%.2f\n" ( n*n / 2 / pi ) 
	main
Advertisements

May 31, 2011 - Posted by | Programming | ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: