Created
May 30, 2014 13:37
-
-
Save sangkeon/7b187f2a8f2cdb4a58f7 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 Main { | |
def solve(nl : List[Double], kl: List[Double]) = { | |
val dwar = (nl.sorted zip kl.sorted).filter(t => t._1 > t._2).size | |
def solveWarKwin(nl : List[Double], kl: List[Double]):Int = { | |
if(nl.size == 1) { | |
if(nl.head < kl.head) 1 else 0 | |
} else if (nl.size == 0 ){ | |
0 | |
} else { | |
kl.sorted.find( _ > nl.head ) match { | |
case Some(x) => 1 + solveWarKwin(nl.tail, (kl.toSet -x).toList) | |
case None => 0 + solveWarKwin(nl.tail, kl.sorted.tail) | |
} | |
} | |
} | |
val war = kl.size - solveWarKwin(nl,kl) | |
//(nl.sorted zip kl.sorted).filter(t => t._1 < t._2).size | |
(dwar, war) | |
} | |
def main(args: Array[String]): Unit = { | |
println(solve(List(0.5,0.1,0.9), List(0.6,0.4,0.3))) | |
println(solve(List(0.186, 0.389, 0.907, 0.832, 0.959, 0.557, 0.300, 0.992, 0.899), | |
List(0.916, 0.728, 0.271, 0.520, 0.700, 0.521, 0.215, 0.341, 0.458))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment