Description

Input

Output

Sample Input

Sample Output

分析:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
struct node {
int x, y;
};
node g[1111];
double posr[1111], posl[1111];
int n, d, ans;
int cmp (node a, node b) {
if (a.x == b.x) return a.y > b.y;
return a.x < b.x;
}
double fx (node x) {
double k = sqrt (1.*d * d - x.y * x.y);
return k;
}
int main() {
for (int t = 1; cin >> n >> d; t++) {
if (n == 0 && d == 0) break;
ans = 0;
for (int i = 1; i <= n; i++) {
cin >> g[i].x >> g[i].y;
if (g[i].y > d) ans = -1;
}
if (ans == 0) {
sort (g + 1, g + 1 + n, cmp);
if (n >= 1) {
posl[++ans] = g[1].x - fx (g[1]);
posr[ans] = g[1].x + fx (g[1]);
}
for (int i = 2; i <= n; i++) {
if (g[i].x == g[i - 1].x) continue;
if (g[i].x - fx (g[i]) > posr[ans]) {
posl[++ans] = g[i].x - fx (g[i]), posr[ans] = g[i].x + fx (g[i]);
continue;
}
posl[ans] = max (posl[ans], g[i].x - fx (g[i]) ), posr[ans] = min (posr[ans], g[i].x + fx (g[i]) );
}
}
printf ("Case %d: %d\n", t, ans);
}
return 0;
}
http://www.cnblogs.com/keam37/ keam所有 转载请注明出处
05-14 16:37