Last active
April 10, 2016 07:41
-
-
Save kijuky/2758ee83fab60a56889c932249ce9f67 to your computer and use it in GitHub Desktop.
GCJ2016 QR
This file contains hidden or 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 QRA extends App { | |
val src = new java.util.Scanner(System.in) | |
val t = src.nextInt() | |
(1 to t).foreach { t => | |
val n = src.nextInt() | |
val answer = n match { | |
case 0 => "INSOMNIA" | |
case n => | |
def sheeps(s: Int, m: Set[Char]): Stream[(Int, Set[Char])] = | |
(s -> m) #:: sheeps(s + n, m ++ (s + n).toString) | |
sheeps(0, Set()) | |
.dropWhile(_._2.size < 10) | |
.head._1 | |
} | |
println(s"Case #${t}: ${answer}") | |
} | |
} |
This file contains hidden or 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 QRB extends App { | |
val src = new java.util.Scanner(System.in) | |
val t = src.nextInt() | |
(1 to t).foreach { t => | |
val s = src.next() | |
val answer = s.sliding(2).map(_.toSet).filter(_.size == 2).size + (if (s.last == '-') 1 else 0) | |
println(s"Case #${t}: ${answer}") | |
} | |
} |
This file contains hidden or 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 QRB extends App { | |
val src = new java.util.Scanner(System.in) | |
val t = src.nextInt() | |
(1 to t).foreach { t => | |
val s = src.next() | |
val answer = (s + '+').sliding(2).map(_.distinct).filter(_.size == 2).size | |
println(s"Case #${t}: ${answer}") | |
} | |
} |
This file contains hidden or 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 QRC extends App { | |
val src = new java.util.Scanner(System.in) | |
val t = src.nextInt() | |
(1 to t).foreach { t => | |
val n = src.nextInt() | |
val j = src.nextInt() | |
val limit = 20 | |
val answer = Stream.from(0) | |
// make jamcoin candidate. | |
.map(Integer.toBinaryString) | |
.map(s"1%${n - 2}s1".format(_)) | |
.map(_.replace(' ', '0')) | |
// interpretation in each base from 2 to 10. | |
.map(s => s -> (2 to 10).map(BigInt(s, _))) | |
// including a nontrivial divisor. | |
.map(t => t._1 -> t._2.flatMap(v => Stream.from(2).takeWhile(_ < limit).find(v.gcd(_) > 1))) | |
.filter(_._2.size == 9) | |
// produce j different jamcoins. | |
.take(j) | |
// output. | |
.map { case (jamcoin, divisors) => "%s %s".format(jamcoin, divisors.mkString(" ")) } | |
println(s"Case #${t}:") | |
answer.foreach(println) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment