Created
April 13, 2014 02:18
-
-
Save Denommus/10566142 to your computer and use it in GitHub Desktop.
Problem B for qualification round of Google Code Jam 2014
This file contains hidden or 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
| #!/usr/bin/sbcl --script | |
| (setf *read-default-float-format* 'double-float) | |
| (defun calculate-time (c f x) | |
| (labels ((calculate-time-helper (c f x n time-spent) | |
| (let* ((time-with-current (/ x (+ (* n f) 2))) | |
| (time-for-farm (/ c (+ (* n f) 2))) | |
| (time-with-farm (+ time-for-farm | |
| (/ x (+ (* (1+ n) f) 2))))) | |
| (if (> time-with-farm time-with-current) | |
| (+ time-spent time-with-current) | |
| (calculate-time-helper c f x (1+ n) (+ time-spent | |
| time-for-farm)))))) | |
| (calculate-time-helper c f x 0 0))) | |
| (with-open-file (in (cadr *posix-argv*) :direction :input) | |
| (with-open-file (out "output" :direction :output :if-exists :supersede) | |
| (loop with cases = (read in) | |
| for case from 1 upto cases | |
| for c = (read in) | |
| for f = (read in) | |
| for x = (read in) | |
| do (format out "Case #~D: ~7$~%" case (calculate-time c f x))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment