Skip to content

Instantly share code, notes, and snippets.

@koduki
Created March 14, 2010 15:34
Show Gist options
  • Save koduki/332032 to your computer and use it in GitHub Desktop.
Save koduki/332032 to your computer and use it in GitHub Desktop.
object ExploringCaves extends Application {
class Vector(var x:Int, var y:Int){ def r = x*x + y*y}
def solv(logs:List[(Int, Int)]) = {
var m = new Vector(0, 0);
var c = new Vector(0, 0);
def f(dx:Int, dy:Int){
c.x += dx
c.y += dy
if((c.r > m.r) || ((c.r == m.r) && (c.x > m.x))){
m.x = c.x
m.y = c.y
}
}
for(log <- logs){ f(log._1, log._2) }
(m.x, m.y)
}
def getLogs(in:java.util.Scanner) = {
def parse(list:List[(Int, Int)]):List[(Int, Int)] = {
(in.nextInt, in.nextInt) match {
case (0, 0) => list
case (x, y) => parse(list + (x, y))
}
}
parse(List[(Int, Int)]())
}
val in = new java.util.Scanner(System.in)
val n = in.nextInt()
val dataset = for(i <- (1 to n)) yield getLogs(in)
dataset.
map(logs => solv(logs)).
foreach( r => printf("%d %d\n", r._1, r._2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment