Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created November 21, 2014 13:32
Show Gist options
  • Save waynejo/9524611687277abadff7 to your computer and use it in GitHub Desktop.
Save waynejo/9524611687277abadff7 to your computer and use it in GitHub Desktop.
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
})
}
@swkimme
Copy link

swkimme commented Nov 21, 2014

정답도 구해지는 답안 첨부합니다~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment