forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10245.cpp
56 lines (49 loc) · 872 Bytes
/
10245.cpp
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
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-6
struct Point
{
double x, y;
double dist(const Point &a)
{
return hypot(a.x - x, a.y - y);
}
} point[10000];
int main()
{
int n;
while (scanf("%d", &n) == 1 && n)
{
for (int i = 0; i < n; i++)
{
scanf("%lf%lf", &point[i].x, &point[i].y);
}
sort(point, point + n, [](const Point &a, const Point &b) -> bool
{
return a.x < b.x;
});
double ans = 10000.0f;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
// dist > this pt + shortest dist; two pts cannot be < curr shortest dist
if (point[i].x + ans < point[j].x)
{
break;
}
double d = point[i].dist(point[j]);
ans = min(ans, d);
}
}
if (fabs(ans - 10000.0f) < EPS)
{
printf("INFINITY\n");
}
else
{
printf("%.4lf\n", ans);
}
}
return 0;
}