// Inspection site: greedy Algorithm There are N closed intervals on the digital axis [ai; bi]. Take as few points as possible, so that each interval has at least one point (the points contained in different ranges can be the same) // submission: Wrong answer three times, cause: define TMP as int // harvest: The key is how to sort by the right endpoint from small to large. If the right endpoint is equal, sort by the Left endpoint from large to small. this question can only be sorted by right endpoint. // AC code # include <stdio. h> # include <stdlib. h> # include <algorithm> # include <math. h> using namespace STD; int N, D; struct line {double left, right ;}; line ln [1005]; int CMP (line A, line B) {if (. right <B. right) return 1; // else if (. right = B. right) {// return. left> B. left; //} return 0;} int main () {INT cases = 0; while (scanf ("% d", & N, & D )) {If (n = 0 & D = 0) break; cases ++; int I, X, Y; bool flag = false; for (I = 0; I <n; I ++) {scanf ("% d" , & X, & Y); If (Y> d) Flag = true; Ln [I]. left = x-SQRT (D * D-y * y) * 1.0); Ln [I]. right = x + SQRT (D * D-y * y) * 1.0);} If (! Flag) {sort (LN, LN + N, CMP); int res = 1; // blind. Here it is written as int double TMP = ln [0]. right; for (I = 1; I <n; I ++) {If (Ln [I]. left <= TMP & ln [I]. right> = TMP) continue; else {TMP = ln [I]. right; Res ++ ;}} printf ("case % d: % d \ n", cases, Res);} else {printf ("case % d: -1 \ n ", cases) ;}} return 0 ;}