标签:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 77074 | Accepted: 17265 |
Description
Input
Output
Sample Input
3 2 1 2 -3 1 2 1 1 2 0 2 0 0
Sample Output
Case 1: 2 Case 2: 1
Source
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 1000+5;
int n, d;
int x[MAXN], y[MAXN];
pair<double, double> p[MAXN];
void solve()
{
double offset;
for(int i = 0; i < n; ++i){
if(d < y[i]){
printf("-1\n");
return;
}
offset = sqrt(d*d-y[i]*y[i]);
p[i].first = x[i]-offset;
p[i].second = x[i]+offset;
}
sort(p, p+n);
int res = 1;
double l = p[0].first, r = p[0].second;
for(int i = 1; i < n; ++i){
if(p[i].first > r){
++res;
l = p[i].first;
r = p[i].second;
}
else{
l = max(l, p[i].first);
r = min(r, p[i].second);
}
}
printf("%d\n", res);
}
int main()
{
int cn = 0;
while(scanf("%d%d", &n, &d), n){
for(int i = 0; i < n; ++i)
scanf("%d%d", &x[i], &y[i]);
printf("Case %d: ", ++cn);
solve();
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/inmoonlight/p/5837804.html