範例程式碼 uva1193

//uva1193
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

bool cmp(vector<double> &v1, vector<double> &v2) {
	return ( v1[1] < v2[1] );
}

int main() {
	int n, total, idx, count = 0;
	double temp, d, dd, x, y;
	vector< vector<double> > dot;

	while (cin >> n >> d) {
		++count;
		if (n == 0 && d == 0)
			break;

		dd = d * d;
		total = 0;
		for (int i = 0; i < n; ++i) {
			cin >> x >> y;
			temp = dd - y * y;
			if (temp < 0.0)
				total = -1;
			else {
				temp = sqrt(temp);
				dot.push_back( vector<double>{x - temp, x + temp} );
			}
		}
		
		if (total == 0) {
			sort(dot.begin(), dot.end(), cmp);
			
			idx = 0;
			while (idx < n) {
				++total;
				x = dot[idx][1];
				++idx;
				while (idx < n && dot[idx][0] <= x)
					++idx;
			}
		}

		dot.clear();
		cout << "Case " << count << ": " << total << endl;
	}


	return 0;
}