Skip to content

Instantly share code, notes, and snippets.

@amutake
Created June 1, 2013 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amutake/5689893 to your computer and use it in GitHub Desktop.
Save amutake/5689893 to your computer and use it in GitHub Desktop.
module Main where
import Control.Applicative ((<$>))
import Control.Monad (forM)
type Pos = (Int, Int)
main :: IO ()
main = do
n <- read <$> getLine
movess <- forM [1..n] $ \_ -> getMoves
let ans = map (solve (0, 0) (0, 0)) movess
mapM_ disp ans
getMoves :: IO [Pos]
getMoves = do
[x, y] <- map read . words <$> getLine
case (x, y) of
(0, 0) -> return []
_ -> ((x, y) :) <$> getMoves
disp :: Pos -> IO ()
disp (x, y) = putStrLn $ show x ++ " " ++ show y
move :: Pos -> Pos -> Pos
move (dx, dy) (x, y) = (x + dx, y + dy)
further :: Pos -> Pos -> Pos
further (x, y) (x', y')
| x + y == x' + y' = if x > x' then (x, y) else (x', y')
| x + y > x' + y' = (x, y)
| otherwise = (x', y')
solve :: Pos -> Pos -> [Pos] -> Pos -- moves -> now -> max -> result
solve _ m [] = m
solve now max' (mv:mvs) =
let next = move mv now in solve next (further next max') mvs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment