Calculate the x-axis range of the radar with the Left and Right coverage at each point, and then calculate the number of required circles.
If the center of the next vertex is prior to the right coordinate of the first vertex in the left coordinate of the X axis, the vertex will be overwritten.
The Code is as follows: (C ++ can pass, G ++ runtime error)
#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int N, R;struct Node{ double l, r; bool operator < (Node t) const { if (r != t.r) { return t.r > r; } }}e[1010];int deal(){ int ans = 1; double pos = e[1].r; for (int i = 2; i <= N; ++i) { if (e[i].l > pos) { ++ans; pos = e[i].r; } } return ans;}int main(){ int x, y, flag, ca = 0; while (scanf("%d %d", &N, &R), N|R) { flag = 0; for (int i = 1; i <= N; ++i) { scanf("%d %d", &x, &y); if (y > R) { flag = 1; } else { double dis = sqrt(double(R*R-y*y); e[i].l = x - dis; e[i].r = x + dis; } } printf("Case %d: ", ++ca); if (flag) { puts("-1"); } else { sort(e+1, e+1+N); int t = deal(); printf("%d\n", t); } } return 0;}