Skip to content

Instantly share code, notes, and snippets.

@waynejo
Last active October 9, 2015 12:14
Show Gist options
  • Save waynejo/6b79bca9f419f0d554e8 to your computer and use it in GitHub Desktop.
Save waynejo/6b79bca9f419f0d554e8 to your computer and use it in GitHub Desktop.
package Main
import java.io.{FileOutputStream, FileInputStream}
import scala.io.StdIn
object Main extends App {
Console.setIn(new FileInputStream("example.in"))
Console.setIn(new FileInputStream("B-large-practice.in"))
Console.setOut(new FileOutputStream("B-large-practice.out"))
def solve(li:Int, ri:Int, ai:Array[Int]):Double = {
Math.exp(ai.slice(li, ri + 1).map(Math.log(_)).sum / (ri - li + 1))
}
val cases = StdIn.readLine().toInt
(1 to cases) foreach { n =>
val Array(_, m) = StdIn.readLine().split(" ").map(_.toInt)
val ai = StdIn.readLine().split(" ").map(_.toInt)
println(s"Case #$n:")
(1 to m) foreach ( v => {
val Array(li, ri) = StdIn.readLine().split(" ").map(_.toInt)
println(solve(li, ri, ai))
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment