-
-
Save theodoreLee/487a5849065c5507c22d 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 | |
import scala.io.Source | |
object Battleship { | |
val INPUT = "A-large-practice.in" | |
val OUTPUT = INPUT.takeWhile(_ != '.') + ".out" | |
val isConsole = false | |
def main(args: Array[String]): Unit = { | |
val itr = Source.fromFile(INPUT).getLines() | |
val stream = if (isConsole) Console.out else new FileOutputStream(OUTPUT) | |
try { | |
Console.withOut(stream) { | |
val sets = itr.next().toInt | |
(1 to sets).foreach { set => | |
val Array(r,c,w) = itr.next().split(' ').map(_.toInt) | |
println(f"Case #$set: ${minimumScore(r, c, w)}") | |
} | |
} | |
} finally { | |
stream.flush() | |
if (!isConsole) stream.close() | |
} | |
} | |
def minimumScore(R:Int, C:Int, W:Int) = { | |
val mod = if(C % W == 0) 1 else 0 | |
R * (C / W) + W - mod | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment