Skip to content

Instantly share code, notes, and snippets.

@ypsilon-takai
Created September 13, 2011 10:15
Show Gist options
  • Save ypsilon-takai/1213536 to your computer and use it in GitHub Desktop.
Save ypsilon-takai/1213536 to your computer and use it in GitHub Desktop.
GCJJ Practice3
(defn jc-queue [one-set]
(flatten (repeat one-set)))
(defn run-jc [k q N]
"run jetcoaster once and returns revenue in euro"
(loop [seats k, rest k, queue q, revenue 0, group-num N]
(if (or
(< rest (first queue))
(<= group-num 0))
[revenue queue]
(recur seats
(- rest (first queue))
(next queue)
(+ revenue (first queue))
(dec group-num)))))
(defn jc-total-revenue [rkn list]
(let [[R k N] rkn]
(loop [rest R, total 0, queue (jc-queue list)]
(if (<= rest 0)
total
(let [[rev next-queue] (run-jc k queue N)]
(recur (dec rest) (+ total rev) next-queue))))))
;; (time (gcj-create-ans-ml
;; "D:/Profiles/q3197c/workspace/C-small-practice.in"
;; "D:/Profiles/q3197c/workspace/C-small-practice.out"
;; jc-total-revenue
;; 2))
;; "Elapsed time: 384.943618 msecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment