Skip to content

Instantly share code, notes, and snippets.

@specdrake
Created May 30, 2020 18:36
Show Gist options
  • Save specdrake/fdf19e8cdc7eb91ed65869dfefb9317b to your computer and use it in GitHub Desktop.
Save specdrake/fdf19e8cdc7eb91ed65869dfefb9317b to your computer and use it in GitHub Desktop.
module Main where
import Data.Char
main :: IO ()
main = do
lf <- getLine
ls <- getLine
let m = (words lf) !! 0
let n = (words lf) !! 1
let r = (words lf) !! 2
let m1 = (words ls) !! 0
let n1 = (words ls) !! 1
let m2 = (words ls) !! 2
let n2 = (words ls) !! 3
putStrLn . show $ solve (read m) (read n) (read r) (read m1) (read n1) (read m2) (read n2)
solve :: Int -> Int -> Double -> Int -> Int -> Int -> Int -> Double
solve m n r m1 n1 m2 n2
| m1 == m2 && n1 == n2 = fromIntegral 0
| m1 == m2 = fromIntegral (abs (n1 - n2)) * (r / fromIntegral n)
| n1 == n2 = min (fromIntegral (abs (m1 - m2)) * pi * part1 * (fromIntegral n1) / (fromIntegral m)) (part1 * fromIntegral (n1 + n2))
| m1 > m2 && n1 > n2 = min (part1 + part2) (part1 * fromIntegral (n1 + n2))
| m1 > m2 && n1 < n2 = min (part3) (part1 * fromIntegral (n1 + n2))
| m1 < m2 && n1 > n2 = solve m n r m2 n2 m1 n1
| m1 < m2 && n1 < n2 = solve m n r m2 n2 m1 n1
where part1 = r / fromIntegral n
part2 = (pi * part1 * fromIntegral (n1 - 1) / (fromIntegral m)) + solve m n r (m1 - 1) (n - 1) m2 n2
part3 = (pi * part1 * fromIntegral n1 / (fromIntegral m)) + solve m n r (m1 - 1) n1 m2 n2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment