-
-
Save KimDaesap/6590a394d9d0600464e8 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.PrintWriter | |
object Codejam { | |
// Config. | |
val inputFilePath = "B-large-practice.in" | |
val outputFilePath = "B-large-practice.out" | |
val isConsole = false | |
// Main procedure. | |
def main(args: Array[String]): Unit = { | |
val inputLines = scala.io.Source.fromFile(inputFilePath).getLines() | |
val inputCount = inputLines.next.toInt | |
val writer = if (isConsole) new PrintWriter(scala.Console.out) | |
else new PrintWriter(outputFilePath) | |
try { | |
process(inputCount, inputLines)(writer.println) | |
} finally { | |
writer.flush() | |
writer.close() | |
} | |
} | |
// Process input value. | |
def process(inputCount: Int, inputLines: Iterator[String])(lineOut: String => Unit) = { | |
for (num <- 1 to inputCount) { | |
val Array(n, m) = inputLines.next().split(" ").map(_.toInt) | |
val as = inputLines.next().split(" ").map(_.toInt) | |
lineOut(s"Case #$num:") | |
for (i <- 0 until m){ | |
val Array(l,r) = inputLines.next().split(" ").map(_.toInt) | |
val logVol = as.slice(l,r + 1).map(Math.log(_)).sum | |
val edge = Math.exp(logVol.toDouble / (r - l + 1).toDouble) | |
lineOut(f"${edge}%.9f") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment