Created
April 16, 2012 12:49
-
-
Save mtgto/2398580 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
import math._ | |
import collection.mutable._ | |
object Main { | |
def main(args: Array[String]) { | |
val sc = new java.util.Scanner(System.in) | |
val T = sc.nextInt() | |
for (t <- 1 to T) { | |
val H = sc.nextInt() | |
val W = sc.nextInt() | |
val D = sc.nextInt() | |
val table = Array.ofDim[Boolean](H-2, W-2) | |
var pos = (0.0, 0.0) | |
for (y <- 0 to H-1) { | |
val chars = sc.next().toCharArray() | |
if (y > 0 && y < H-1) { | |
for (x <- 1 to W-2) { | |
//println("x="+x+",y="+y) | |
if (chars(x) == 'X') { | |
// 左上を原点 | |
pos = (y-0.5, x-0.5) | |
//println("x="+pos._2+",y="+pos._1) | |
} | |
} | |
} | |
} | |
var ans = 0 | |
val checks = HashSet.empty[Double] | |
def check(y: Int, x: Int) = { | |
val ry = y*(H-2) + (if (y%2==0) pos._1 else H-2 - pos._1) | |
val rx = x*(W-2) + (if (x%2==0) pos._2 else W-2 - pos._2) | |
val atan = atan2(ry-pos._1, rx-pos._2) | |
if (!checks(atan)) { | |
checks += atan | |
val len = (rx-pos._2)*(rx-pos._2)+(ry-pos._1)*(ry-pos._1) | |
if (len <= D*D) { | |
//println("rx="+rx+",ry="+ry+",len="+len) | |
ans += 1 | |
} | |
} | |
} | |
for (j <- 0 to D) { | |
for (i <- 0 to D; if (j != 0 || i != 0)) { | |
check(j, i) | |
check(-j, i) | |
check(j, -i) | |
check(-j, -i) | |
} | |
} | |
println("Case #" + t + ": " + ans) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment