Comment detail

情報オリンピック2007年度国内予選問題3 (Nested Flatten)

turn == True => 太郎のターン

turn == False => 花子のターン

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import List
import Control.Monad

main :: IO ()
main = do n <- readLn
          c1 <- liftM sort $ sequence $ replicate n readLn
          let c2 = filter (`notElem` c1) [1..2*n]
              (a, b) = solve c1 c2 0 True
          mapM_ print [a, b]

solve :: [Int] -> [Int] -> Int -> Bool -> (Int, Int)
solve xs [] _ turn | turn       = (0, length xs) -- Hanako won
                   | otherwise  = (length xs, 0) -- Taro won
solve xs ys card turn =
    case break (card <) xs of
      (_, []) -> solve ys xs 0 (not turn)
      (small, x:big) -> solve ys (small++big) x (not turn)

Index

Feed

Other

Link

Pathtraq

loading...