Created
April 28, 2013 07:10
-
-
Save papamitra/5476164 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
import Control.Monad(forM_) | |
import Text.Printf | |
main :: IO() | |
main = do | |
txt <- getContents | |
let ls = lines txt | |
num = head ls | |
ps = mklist $ tail ls | |
forM_ (zip ps [1..(length ps)]) $ \(p,i) -> | |
printf "Case #%d: %d\n" i (solve p) | |
--forM_ ps (putStrLn . show . solve) | |
--solve :: [Int] -> Int | |
solve [r,t] = proc' 1 (t `div` r) | |
where | |
proc' lef rig = case rig - lef of | |
d | |
| (abs d) <= 1 -> lef | |
_ -> let m = (lef + rig) `div` 2 | |
sq = 2*(m^2) + (2*r-1)*m | |
in if sq <= t then proc' m rig | |
else proc' lef m | |
mklist :: [String] -> [[Integer]] | |
mklist xs = map (map read . words) xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment