-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathtyama_PKU1328.cpp
More file actions
45 lines (41 loc) · 849 Bytes
/
tyama_PKU1328.cpp
File metadata and controls
45 lines (41 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <vector>
#include <algorithm>
#include <utility>
#include <cstdio>
#include <cmath>
using namespace std;
#define x first
#define y second
#define adjacent(a,b) sqrt((a)*(a)-(b)*(b))
int main(){
int c=1,n,r,x,y,f;
vector< pair<int,int> > v;
for(;scanf("%d%d",&n,&r),n;c++){
f=0;v.clear();
printf("Case %d: ",c);
//input
for(;n;n--){
scanf("%d%d",&x,&y);
if(y>r)f=1;
v.push_back(make_pair(x,y));
}
if(f){puts("-1");continue;}
sort(v.begin(),v.end());
//check
while(v.size()){
double a=adjacent(r,v[0].y),m=v[0].x-a,M=v[0].x+a;
v.erase(v.begin());
while(v.size()){
a=adjacent(r,v[0].y);
double m2=v[0].x-a,M2=v[0].x+a;
m=max(m,m2);
M=min(M,M2);
if(M<m)break;
v.erase(v.begin());
}
n++;
}
printf("%d\n",n);
}
return 0;
}