Sort by

recency

|

72 Discussions

|

  • + 0 comments

    my haskell solution:

    import Control.Monad 
    
    euclidean[x1,y1] [x2,y2] = sqrt $ (x2 - x1)**2 + (y2 - y1)**2
    
    solve n points = sum $ zipWith euclidean pairs (tail pairs ++ [head pairs])
      where
        pairs = map ((\[a, b] -> [read a, read b]) . words) points :: [[Double]]
    
    main = do
        n <- readLn :: IO Int 
        input <- replicateM n getLine
        print $ solve n input
    
  • + 0 comments

    The question doesn't make clear that the points are already in counterclockwise order. I was staring at the problem for a while wondering how I'm suppose to order the list of points until I looked and saw that the other solutions didn't do anything special (besides calculate the distance between the points and sum them together).

  • + 0 comments

    In this article, we’ll explore the significance of girth the materials used in their construction, and how they help prevent leaks.

  • + 0 comments

    F#

    open System
    
    let readPoint _ =
        Console.ReadLine().Split ' '
        |> Array.toList
        |> List.map float
    
    let glue list = List.append list [ list.Head ]
    
    let readPoints n = [ 1..n ] |> List.map readPoint |> glue
    
    let toDistance ([ x1; y1 ], [ x2; y2 ]) =
        ((x2 - x1) ** 2.0 + (y2 - y1) ** 2.0) ** 0.5
    
    [<EntryPoint>]
    let main argv =
        Console.ReadLine()
        |> int
        |> readPoints
        |> List.pairwise
        |> List.map toDistance
        |> List.sum
        |> Console.WriteLine
    
        0
    
  • + 0 comments
    import Control.Monad (replicateM)
    
    -- Enter your code here. Read input from STDIN. Print output to STDOUT
    
    solve pairs = sum lengths
                where lines                    = zip pairs (tail pairs ++ [head pairs])
                      dst ( (x1,y1), (x2,y2) ) = ((x1 - x2)**2 + (y1 - y2)**2)**0.5
                      lengths                  = map (dst) lines
    main = do
        let toInt s  = read s :: Int
        let toDoub s = read s :: Double
        lines <- getLine >>= (\line -> return $ toInt line) >>= (\n -> replicateM n getLine)
        let pairs = map (\[x,y] -> (toDoub x, toDoub y)) . map words $ lines
        print (solve pairs)