Greedy. After a long time, I am confused. I just found that zoj also has this question. By the way,.
Start to get greedyAlgorithmIf a new vertex is encountered, the new vertex is taken as the leftmost Vertex on the circle .. In fact, it is wrong, because in some cases, the last circle can be completely shifted to the right and then overwritten.
So my algorithm is: Take the first point as the left end point of the circle, find the center of the center, and then look at the next point. If this point is not in the circle above, the current point is used as the left endpoint as a center. If the center can cover all the points covered by the previous circle, it is equivalent to moving the circle to the right.
If the coverage is incomplete, a circle is made at the left endpoint of the point.
The complexity is not very good. The worst visual indicator is n ^ 2 ..
# Include <set> # include <map> # include <queue> # include <stack> # include <cmath> # include <cstdio> # include <cstdlib> # include <iostream> # include <climits> # include <cstring> # include <string> # include <algorithm> # define mid (X, y) (x + y)> 1) # define L (x) (x <1) # define R (x) (x <1 | 1) # define for (I, S, T) for (INT I = (s); I <(t); I ++) # define bug puts ("here !!! ") # Define stop system (" pause ") # define file_r (x) freopen (x," r ", stdin) # define file_w (x) freopen (X, "W", stdout) using namespace STD; const int max = 1010; struct point {int X, Y; bool operator <(const point & A) const {if (. X = x) return Y <. y; return x <. X ;}}; point P [Max]; int ind [Max]; int f [Max]; void rcenter (point P, double & CX, int D) {cx = P. X + SQRT (D * D-P. y * P. y * 1.0);} bool notin (point P, double CX, int d) {return (P. x-cx) * (p. x-cx) + P. y * P. y> D * D;} bool cancover (INT ans, double CX, int d) {int I = f [ANS]; while (IND [I] = ans) {If (notin (P [I ++], CX, d) return false;} return true;} int solve (INT N, int d) {memset (IND, 0, sizeof (IND); int ans = 1; sort (p, p + n); If (P [0]. y> d) return-1; ind [0] = 1; F [1] = 0; double CX; rcenter (P [0], CX, d ); for (I, 1, n) {If (ABS (P [I]. y)> d) return-1; if (notin (P [I], CX, d) {double T = Cx; rcenter (P [I], T, d); If (cancover (ANS, T, d) {cx = T; ind [I] = ans;} else {ans ++; rcenter (P [I], CX, d); ind [I] = ans; F [ANS] = I ;}} else {Ind [I] = ans ;}} return ans ;} int main () {int N, D; int ncases = 1; while (CIN> N> d) {If (n = 0 & D = 0) break; for (I, 0, n) CIN> P [I]. x> P [I]. y; cout <"case" <ncases ++ <":"; if (d <= 0) {cout <-1 <Endl; continue ;} int ans = solve (n, d); cout <ans <Endl;} return 0 ;}