2008-11-14から1日間の記事一覧

Problem 81

http://projecteuler.net/index.php?section=problems&id=81 ものすごくそのままなDP import Data.Array.IArray import Control.Monad root ::Array (Int,Int) Integer->Array (Int,Int) Integer root cost = r where r = listArray b [c ix | ix <- range b…

Problem 80

http://projecteuler.net/index.php?section=problems&id=80 どっかで調べた開平法を実装。 探索範囲が狭いから楽。 import Data.List root m =root' m 0 root' n a = b : root' n' a' where b = head [c|c<-[9,8..],(a+c)*c < n] n' = (n-(a+b)*b)*100 a' =…

Problem 79

http://projecteuler.net/index.php?section=problems&id=79 とりあえず、最短なので、各数字は高々一回しか現れないと勝手に解釈。 あとはそのまま。 import Data.Char import Data.List import Control.Monad import Data.Graph p079 xs =flip intersect u…

Dijkstra(1対全・最短路)

Dijkstra まだ一度も走らせていない。 たぶんバグあり。 module Dijkstra where import Data.List import Data.Graph import Data.Array.IArray import Debug.Trace import qualified Data.Set as Set type Weight = Array Edge Int -- g=graph, w=weight, d…