#!/usr/bin/env python # Author: Matt Eastman <matt@meastman.org> import math EPSILON = 0.0000000001 def dist(a, b): """Calculate the distance between 2 points.""" return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) def find_circles(a, b, r): """Find up to 2 circles of radius r that touch a and b.""" # See http://stackoverflow.com/questions/3349125/circle-circle-intersection-points ab_dist = dist(a, b) if ab_dist > r * 2 or ab_dist == 0: return [] h = math.sqrt(r ** 2 - ab_dist ** 2 / 4) mid = ((a[0] + b[0]) / 2, (a[1] + b[1]) / 2) x_rhs = h * (b[1] - a[1]) / ab_dist y_rhs = h * (b[0] - a[0]) / ab_dist return set([ (mid[0] + x_rhs, mid[1] - y_rhs), (mid[0] - x_rhs, mid[1] + y_rhs), ]) def points_in_circle(center, r, points): """Determine which points are within a given circle.""" r2 = r ** 2 + EPSILON return [ point for point in points if (point[0] - center[0]) ** 2 + (point[1] - center[1]) ** 2 <= r2 ] def handle_case(opts): r_str, n_str = raw_input().split() r = float(r_str) points = [ tuple(map(float, raw_input().split())) for _ in xrange(int(n_str))] max_hit_count = 0 max_hit_info = (None, []) # Try each zombie as a hit target. # Necessary if no 2 zombies are within 2*r of each other. for point in points: hit = points_in_circle(point, r, points) if len(hit) > max_hit_count: max_hit_count = len(hit) max_hit_info = (point, hit) # For each pair of zombies, there can be up to 2 circles of radius r that # touch both points/zombies. # Try the center of each of these as a hit target. for a_i, a in enumerate(points): for b in points[a_i + 1:]: for center in find_circles(a, b, r): hit = points_in_circle(center, r, points) if len(hit) > max_hit_count: max_hit_count = len(hit) max_hit_info = (center, hit) print max_hit_count if opts.debug: center, hit_points = max_hit_info print 'center: %r' % (center, ) for point in hit_points: print ' hit: %r (dist: %r)' % (point, dist(point, center)) print def main(): try: import argparse except ImportError: class opts: debug = False else: parser = argparse.ArgumentParser() parser.add_argument('--debug', default=False, action='store_true') opts = parser.parse_args() for case_num in xrange(int(raw_input())): handle_case(opts) main()