import java.util.Scanner import scala.collection.{mutable => mu} object Problem202 { type Index = (Int, Int) type Point = (Int, Int) def overlap(a: Point, b: Point): Boolean = { Math.pow(a._1 - b._1, 2.0) + Math.pow(a._2 - b._2, 2.0) < 400 } def proc(coins: Seq[Point]): Int = { val S = new mu.HashMap[Index, mu.HashSet[Point]]() def overlapCoin(coin: Point, index: Index): Boolean = { val (px, py) = (index._1, index._2) for { pxi <- px - 1 to px + 1 pyi <- py - 1 to py + 1 points <- S.get(pxi, pyi) point <- points if overlap(coin, point) } { return true } false } def putCoin(coin: Point): Unit = { val index = (coin._1 / 20, coin._2 / 20) if (!overlapCoin(coin, index)) { if (!S.contains(index)) { S += index -> mu.HashSet[Point]() } S(index) += coin } } coins.foreach { coin => putCoin(coin) } S.map(_._2.size).sum } def main(args: Array[String]) { val sc = new Scanner(System.in) val n = sc.nextInt() val coins = Array.fill(n)((sc.nextInt(), sc.nextInt())) val result = proc(coins) println(result) } }