2 0 0 1 1 2 1 1 1 1 3 -1.5 0 0 0 0 1.5 0
0.71 0.00 0.75
import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.FileReader; import java.io.StreamTokenizer; import java.io.PrintWriter; import java.io.InputStream; import java.io.FileInputStream; import java.io.OutputStreamWriter; import java.io.File; import java.util.Scanner; import java.util.ArrayList; import java.util.List; import java.util.Collections; import java.util.Arrays; import java.util.Comparator; import java.util.Formatter; class Main { public static final boolean DEBUG = true; public int n; public Point[] p; public Scanner cin; public Comparator<Point> cmpy = new Comparator<Point>() { public int compare(Point a, Point b) { if (a.y < b.y) return -1; else if (Math.abs(a.y - b.y) < 1e-9) return 0; else return 1; } }; public Comparator<Point> cmpx = new Comparator<Point>() { public int compare(Point a, Point b) { if (a.x < b.x) return -1; else if (Math.abs(a.x - b.x) < 1e-9) return 0; else return 1; } }; class Point { double x, y; } public void init() throws IOException { if (DEBUG) { cin = new Scanner(new FileReader("d:\\OJ\\uva_in.txt")); } else { cin = new Scanner(System.in); } } public boolean input() throws IOException { n = cin.nextInt(); if (n == 0) return false; p = new Point[n]; for (int i = 0; i < n; i++) { p[i] = new Point(); p[i].x = cin.nextDouble(); p[i].y = cin.nextDouble(); } return true; } public double dis(Point a, Point b) { double x = a.x - b.x; double y = a.y - b.y; return Math.sqrt(x * x + y * y); } public double closestPair(int l, int r) { if (r - l == 1) { return dis(p[l], p[r]); } else if (r - l == 2) { double d1 = dis(p[l], p[l + 1]); double d2 = dis(p[l + 1], p[r]); double d3 = dis(p[l], p[r]); return Math.min(d1, Math.min(d2, d3)); } int m = (l + r) >> 1; double dm = Math.min(closestPair(l, m), closestPair(m + 1, r)); List<Point> q = new ArrayList<Point>(); for (int i = l; i <= r; i++) { if (Math.abs(p[i].x - p[m].x) < dm) q.add(p[i]); } Collections.sort(q, cmpy); int size = q.size(); for (int i = 0; i < size; i++) { for (int j = i + 1; j < size && q.get(j).y - q.get(i).y < dm; j++) { double tmp = dis(q.get(j), q.get(i)); dm = Math.min(tmp, dm); } } return dm; } public double solve() { Arrays.sort(p, cmpx); double ans = closestPair(0, n - 1); return ans / 2; } public static void main(String[] args) throws IOException { Main solver = new Main(); solver.init(); while (solver.input()) { double ans = solver.solve(); //System.out.printf("%.2f\n", ans); Formatter fmt = new Formatter(); fmt.format("%.2f", ans); System.out.println(fmt); } } }