-
-
Save bongster/179573b34a920a17b416 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
import java.io.{FileOutputStream, FileInputStream} | |
import scala.io.StdIn | |
/** | |
* Created by bongster on 15. 4. 24.. | |
*/ | |
object HouseOfPancakes extends App{ | |
Console.setIn(new FileInputStream("B-large-practice.in")) | |
Console.setOut(new FileOutputStream("B-large-practice.out")) | |
def solve(pancakes: List[Int], maxIteratorPancakesNum: Int, movePancakeAmount: Int =1, result: Int): Int = { | |
if(movePancakeAmount > maxIteratorPancakesNum) | |
result | |
else{ | |
// 16 , 9 , 4 =>[1] 15, 8, 3 + 1 | |
// 16 , 9 , 4 =>[2] 7, 4, 1 + 2 | |
// 16 , 9 , 4 =>[3] 5, 3, 1 + 3 | |
// 16 , 9 , 4 =>[4] 3, 2, 0 + 4 | |
// 16, 9 , 4 =>[5] 3, 1, 0 + 5 | |
// 16[15] , 9[8] , 4[3] =>[6] | |
// 16[15] , 9[8] , 4[3] =>[7] | |
// 16[15] , 9[8] , 4[3] =>[8] | |
// pancakeNum - 1 / num | |
val spendTimeList = for(pancake <- pancakes) yield { | |
if (pancake -1 > 0) | |
(pancake -1) / movePancakeAmount | |
else | |
0 | |
} | |
val spendTime = movePancakeAmount + spendTimeList.sum | |
solve(pancakes, maxIteratorPancakesNum, movePancakeAmount + 1, Math.min(result, spendTime)) | |
} | |
} | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach ({n=> | |
val diners = StdIn.readLine().toInt | |
val pancakes = StdIn.readLine().split(' ').map(_.toInt).toList | |
println(s"Case #$n: ${solve(pancakes,pancakes.max, result=pancakes.max)}") | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment