結果

問題 No.338 アンケート機能
ユーザー kuwakuwa
提出日時 2016-01-29 22:42:23
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,319 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 160,128 KB
最終ジャッジ日時 2024-04-27 02:17:09
合計ジャッジ時間 1,004 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:44:24: error: [GHC-87543]
    Ambiguous occurrence ‘BC.getLine’.
    It could refer to
       either ‘BC.getLine’,
              imported qualified from ‘Data.ByteString’ at Main.hs:8:1-38,
           or ‘BC.getLine’,
              imported qualified from ‘Data.ByteString.Char8’ at Main.hs:7:1-44.
   |
44 | readInt = parseInt <$> BC.getLine
   |                        ^^^^^^^^^^

Main.hs:47:26: error: [GHC-87543]
    Ambiguous occurrence ‘BC.getLine’.
    It could refer to
       either ‘BC.getLine’,
              imported qualified from ‘Data.ByteString’ at Main.hs:8:1-38,
           or ‘BC.getLine’,
              imported qualified from ‘Data.ByteString.Char8’ at Main.hs:7:1-44.
   |
47 | readInts = parseInts <$> BC.getLine
   |                          ^^^^^^^^^^

ソースコード

diff #

module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
    [a, b] <- readInts
    print $ solve a b

solve :: Int -> Int -> Int
solve a b = rec 1
    where rec m 
            | null cand = rec (m+1) 
            | otherwise = m
              where cand = filter (== (a,b)) $ map percentize $ take (m+1) $ zip [0..] [m,m-1..]
          percentize (a,b) = (roundUpOn5 $ 100 * fromIntegral a / fromIntegral (a + b),
                            roundUpOn5 $ 100 * fromIntegral b / fromIntegral (a + b))

roundUpOn5 :: (RealFrac a, Integral b) => a -> b
roundUpOn5 x
  | n <= -0.5 = m - 1
    | n >= 0.5 = m + 1
      | otherwise = m
        where (m, n) = properFraction x

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Doub le Formatting -}

doubleFormat :: Double -> String
doubleFormat = Text.Printf.printf "%.12f"
0