-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10245 - The Closest Pair Problem.cpp
60 lines (45 loc) · 1.08 KB
/
10245 - The Closest Pair Problem.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
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
double fun (double a, double b)
{
return sqrt(a * a + b * b);
}
int main()
{
int n;
while(cin >> n)
{
if(!n)
break;
vector < pair <double , double > > v, p;
for(int i = 0; i < n; i++)
{
double x, y;
cin >> x >> y;
v.push_back(make_pair(x,y));
}
sort(v.begin(), v.end());
//reverse(v.begin(), v.end());
double sum = 0.0;
vector <double> vx;
double mn = 99999999.00, x, y, res= 0.0;
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
{
double pp, qq ;
pp = abs(v[i].first - v[j].first); qq = abs(v[i].second - v[j].second);
res = fun(pp, qq);
if(res < mn)
{
mn = res;
}
}
}
if(mn >= 10000.00)
printf("INFINITY\n");
else
cout<<fixed << setprecision(4) << mn << endl;
v.clear();
}
}