Created
July 24, 2014 08:45
-
-
Save SilverRainZ/29588300d20f35a53d63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#include <cmath> | |
using namespace std; | |
typedef struct | |
{ | |
int x; | |
int y; | |
}TPoint; | |
int cmp(TPoint a, TPoint b) | |
{ | |
if (a.x != b.x) | |
return a.x > b.x; | |
else return a.y < b.y; | |
} | |
int main() | |
{ | |
freopen("data.txt","r",stdin); | |
int n, dis; | |
TPoint h[1005]; | |
int ans, t = 0; | |
int i, j; | |
double x, l, r; | |
while (scanf("%d%d",&n, &dis) && n && ++t) | |
{ | |
for (i = 0; i < n; i++) | |
scanf("%d%d",&h[i].x, &h[i].y); | |
sort(h, h + n, cmp); | |
if (h[0].y > dis) | |
{ | |
printf("Case %d: -1\n", t); | |
continue; | |
} | |
x = -sqrt(dis*dis - h[0].y*h[0].y) + h[0].x; | |
ans = 1; | |
for (i = 1; i < n; i++) | |
{ | |
if (h[i].y > dis) break; | |
l = -sqrt(dis*dis - h[i].y*h[i].y) + h[i].x; | |
r = sqrt(dis*dis - h[i].y*h[i].y) + h[i].x; | |
// printf("l = %lf, r = %lf, x = %lf\n", l, r, x); | |
if (r < x) | |
{ | |
ans++; | |
x = l; | |
} | |
} | |
if (i != n) printf("Case %d: -1\n", t); | |
else printf("Case %d: %d\n", t, ans); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment