Created
November 21, 2014 13:32
-
-
Save waynejo/9524611687277abadff7 to your computer and use it in GitHub Desktop.
This file contains 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
val input = "2 20 8 2 3 5" | |
val normalSpeed = 0.5f | |
val boostSpeed = 1 | |
val split = input.split(" ").map(_ toInt) | |
val numBoosters = split(0) | |
val constructionTime = split(1) | |
val numStars = split(2) | |
val numDistances = split(3) | |
val distances = split.drop(4) | |
val stars = (0 until numStars).map{i => distances(i % numDistances)}.toList | |
println(stars) | |
val result = (0 until numStars).map{ | |
starToPlaceBooster => | |
stars.zipWithIndex.map{ | |
case (d, index) => | |
if (index == starToPlaceBooster) (index, d, true) else (index, d, false) | |
} | |
} | |
result.foreach(println) | |
def getTime(testSet:List[(Int, Int, Boolean)]):Float = { | |
testSet.foldLeft(0.0f)((accum, x) => { | |
val distance = x._2 | |
val boost = x._3 | |
val result = if (constructionTime > distance * 2 + accum || !boost) { | |
distance / normalSpeed + accum | |
} else if (accum > constructionTime) | |
distance / boostSpeed + accum | |
else { | |
val timeWithoutBoost = constructionTime - accum | |
val distanceWithoutBoost = timeWithoutBoost * normalSpeed | |
val distanceWithBoost = distance - distanceWithoutBoost | |
val timeWithBoost = distanceWithBoost / boostSpeed | |
timeWithoutBoost + timeWithBoost + accum | |
} | |
result | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
정답도 구해지는 답안 첨부합니다~!