Created
March 31, 2013 17:26
-
-
Save jaguilar/5281365 to your computer and use it in GitHub Desktop.
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
hedgemony = (input) -> | |
lines = input.match(/[^\r\n]+/g); | |
numTests = parseInt(lines[0]) | |
formatOutput i, solve lines[2*i] for i in [1..numTests] | |
solve = (line) -> | |
heights = (parseFloat s for s in line.split(" ")) | |
n = 1 | |
while n < heights.length - 1 | |
average = (heights[n-1] + heights[n+1]) / 2.0 | |
heights[n] = if heights[n] > average then average else heights[n] | |
++n | |
heights[heights.length - 2] | |
formatOutput = (problemNumber, solution) -> | |
"Case \##{problemNumber}: #{solution.toFixed(4)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment