Created
June 1, 2013 10:05
-
-
Save amutake/5689893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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