Last active
August 29, 2015 14:02
-
-
Save sungkmi/24bdeb3d86acd71c0bfd 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
object DeceitfulWar extends App { | |
def war(naomiSet: Seq[Double], kenSet: Seq[Double], r: Int = 0): Int = { | |
if(naomiSet.isEmpty) r | |
else if (naomiSet.length == 1) { | |
if (naomiSet.head > kenSet.head) 1 else 0 | |
} | |
else { | |
val largers = kenSet.filter(_>naomiSet.head) | |
if (largers.isEmpty) kenSet.size | |
else war(naomiSet.tail, kenSet diff Seq(largers.head), r+1) | |
} | |
} | |
def dwar(naomi: Seq[Double], ken: Seq[Double]): Int = | |
0 | |
def process(iter: Iterator[String])(pr: String => Unit) = | |
for (i <- 1 to iter.next().toInt) yield { | |
val n = iter.next() | |
val naomi = iter.next().split(' ').map(_.toDouble) | |
val ken = iter.next().split(' ').map(_.toDouble) | |
pr(s"Case #$i: ${dwar(naomi, ken)} ${war(naomi, ken)}") | |
} | |
import java.io._ | |
val out = new PrintStream(new File("d.out")) | |
try { | |
process(io.Source.fromFile("D-small-practice.in").getLines) { s: String => | |
out.println(s) | |
} | |
} finally { | |
out.flush; out.close | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment