-
-
Save bongster/9f175373c3905fcb84f9 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
package main.scala | |
import java.io.{FileOutputStream, FileInputStream} | |
import scala.io.StdIn | |
/** | |
* Created by bongster on 15. 1. 2.. | |
*/ | |
object DataPacking extends App { | |
//println("This is DataPacking") | |
Console.setIn(new FileInputStream("DataPacking/A-large-practice.in")) | |
Console.setOut(new FileOutputStream("DataPacking/A-large-practice.out")) | |
def solve(list1: List[Int], discSize: Int, maxNum: Int = 0): Int = { | |
if (list1.isEmpty) { | |
maxNum | |
} else { | |
list1.tail.zipWithIndex.find(_._1 <= discSize - list1.head) match { | |
case Some((v, i)) => { | |
//println(list1.tail.take(i), list1.tail.takeRight(list1.tail.size - i)) | |
val (before,after) = list1.tail.splitAt(i) | |
solve(before ++ after.tail, discSize,maxNum + 1) | |
//solve(list1.tail.take(i) ::: list1.tail.drop(i + 1), discSize, maxNum + 1) | |
} | |
case None => { | |
solve(list1.tail, discSize, maxNum + 1) | |
} | |
} | |
} | |
} | |
val cases = StdIn.readLine().toInt | |
(1 to cases) foreach { n => | |
//println("gggg") | |
val Array(_, discSize) = StdIn.readLine().split(" ").map(_.toInt) | |
val datas: List[Int] = StdIn.readLine().split(" ").map(_.toInt).toList | |
.sortWith(_ > _) | |
println(s"Case #$n: ${solve(datas, discSize)}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment