No Such Blog or Diary

«Prev || 1 | 2 | 3 |...| 1216 | 1217 | 1218 |...| 1276 | 1277 | 1278 || Next»

風邪か...

完全にのどがやられたようで腫れとる... 自転車での全力疾走が悪かったのだろうか? とりあえず今日はおとなしく寝続けるとしよう.それにしてもラヂヲはあの短さで終わるのだろうか?

S.F. & Tokyo

毒を食らわば皿まで... 6th & 7th City を通販にてゲット.ちぃと高いよ? ま,SHA-1 の Collision search attack を理解したら見るとしよう.

AMラジオって

受信できるデバイスが身の回りに皆無だなぁと初めて認識した.コンポやらラジカセがあれば受信できそうなものだがMP3プレーヤとスピーカで置換されてるし,MP3プレーヤもノイズとかの問題かFMしか受信できないし.明日の夜は需要があるので非常時にも役に立つと信じてラジオを購入.意外と高し.100円ショップとか行けば安く手に入ったのだろうか...?

ICPC by Haskell

ながながとICPC2005 Regional, Tokyo の問題Fを Haskell で.O(n^2) の DP で, 基本的に foldl の2重ネストと.Cで書いた場合と比べて for 文の代わりに foldl になっているだけの違いしかない...

 -- Problem F in ACM/ICPC 2005 ASIA Regional Tokyo
 -- 2005/11/04  O(n^2) DP
import Control.Monad
import Debug.Trace
import List
main = getProblems >>= mapM_ (putStrLn.show.solve)
 
getProblems = 
    do
    [n] <- getNums
    if n==0 then return []
       else do
            xs <- getNums
            b <- liftM (head.map read.words) getLine :: IO(Double)
            [sr,sv,se,sf] <- liftM words getLine
            liftM ((xs, b, read sr, read sv::Double, read se::Double, read sf::Double):) getProblems
    where 
    getNums = liftM (map read.words) getLine :: IO([Int])
 
solve :: ([Int], Double, Int, Double, Double, Double) -> Double
solve (ys,b,r,v,e,f) = sl ys [(0.0,0)] 
    where
    -- xs:rest of checkpoints, cs:best cost for already passed checkpoints 
    sl [] cs = fst $ head cs
    sl (x:xs) cs = sl xs (best x cs:cs)
    -- (best cost, current cost, current point)
    best x cs = (\(bc,c,p) -> (min bc (c + cost (x-p) x),x)) $ foldl op (100000000, 0, x) cs
      where 
      op (cbc, c, p) (bc, pos) = let
                                 c' = c + cost (x-p) (x-pos)
                                 in (min cbc (c'+b+bc), c', pos)
    cost p q = ct p 0.0
      where 
      ct p c = if p == q then c
               else ct (p+1) (c+step p)
      step p = if p < r then 1.0 / (v-f*fromIntegral(r-p))
               else  1.0 / (v-e*fromIntegral(p-r))

逆さにしても英単語になる英単語を

Aspell の英語辞書から単語を抜き出して全探索してみた.登録されている単語数は 141891 らしい.んで,1文字の単語を抜いてさかさまにしても単語があったのは 381 個.うち palindrome になっているものが 112 個.自身にもどらずほかの単語になるのが 269 個.さらに長さが4以上であるものは 137 個(これらの結果は複数形の s や動詞の変化をはじいていない)

よく知った単語の例:

emit ⇔ time

evil ⇔ live

flow ⇔ wolf

keep ⇔ peek

loop ⇔ pool

part ⇔ trap

プログラム結果

ICPC by Haskell

なぜか D を飛ばしてICPC2005 Regional, Tokyo の問題Eを Haskell で.全生成して条件で filter して max とるという非常に美しい形に...

 -- Problem E in ACM/ICPC 2005 ASIA Regional Tokyo
 -- 2005/11/04   Brute Force (42 * 2^5)
import Control.Monad
import Debug.Trace
import List
main = getProblems >>= mapM_ (putStrLn.(\r -> if r < 0 then "-1" else show r).solve)
 
getProblems = 
    do
    n <- liftM (head.map read.words) getLine
    replicateM n getProblem
 
getProblem =
    do
    r <- getNum
    s <- liftM (head.map read.words) getLine
    ws <- replicateM s getNum
    return (r, ws)
    where 
    getNum = liftM (head.map read.words) getLine :: IO(Double)
 
solve :: (Double, [Double])->Double
solve (r, ws) = foldl max (-1.0).filter (<r).map(\(lw, rw)->lw+rw).concat.map genWidth.concat.map genTree.perm $ ws
 
data BTree a = Node a (BTree a) (BTree a)
             | Leaf a
genTree ] = [Leaf
genTree xs = [ Node (weight t + weight u) t u | i <- [1..length xs-1], t<-genTree (take i xs), u<-genTree (drop i xs)]
weight (Leaf x) = x
weight (Node x _ _) = x
genWidth (Leaf x) = [(0.0,0.0)]
genWidth (Node _ l r) = let
                        ls = genWidth l
                        rs = genWidth r
                        lw = weight l
                        rw = weight r
                        la = lw/(lw + rw)
                        ra = 1-la
                        in [x | (ll,lr)<-ls, (rl,rr)<-rs, x<-gen ll lr rl rr la ra]
gen ll lr rl rr la ra = dupFlip (max (la + ll) (rl-ra), max (ra + rr) (lr-la))
dupFlip (x,y) = [(x,y), (y,x)]
perm [] = []
perm ] = [[]
perm (x:xs) = [ take i y ++ (x:drop i y) | y <- perm xs, i <- [1..length xs]]
«Prev || 1 | 2 | 3 |...| 1216 | 1217 | 1218 |...| 1276 | 1277 | 1278 || Next»
Search
Feeds

Page Top