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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| // 42jerrykim.github.io에서 더 많은 정보를 확인 할 수 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Point = pair<ll,ll>;
#define x first
#define y second
istream& operator>>(istream& in, Point& t){ in >> t.x >> t.y; return in; }
Point operator+(Point a, Point b){ return {a.x+b.x, a.y+b.y}; }
Point operator-(Point a, Point b){ return {a.x-b.x, a.y-b.y}; }
ll operator*(Point a, Point b){ return a.x*b.x + a.y*b.y; } // dot
ll operator/(Point a, Point b){ return a.x*b.y - a.y*b.x; } // cross
static inline double length(Point p){ return sqrt((long double)p.x*p.x + (long double)p.y*p.y); }
static inline double dist_point_line(const Point& a, const Point& b, const Point& c){
// |(b-a) x (c-a)| / |b-a|
return fabsl((long double)((b-a)/(c-a))) / length(b-a);
}
// Rotate by +90 degrees with a canonical representative to keep ordering stable
static inline Point Rot90(Point p){
return p.y >= 0 ? Point{p.y, -p.x} : Point{-p.y, p.x};
}
int N;
int Idx[2020], Ord[2020];
Point A[2020];
struct Line{
int i, j, flag; // flag: +1 parallel, -1 perpendicular (=rot90)
Point s, e, dir;
Line(int i_, int j_, int f_) : i(i_), j(j_), flag(f_), s(A[i_]), e(A[j_]){
if(e < s) swap(s, e);
dir = (flag == 1) ? (e - s) : Rot90(e - s);
}
bool operator<(const Line& l) const{
long long cr = dir / l.dir; // angle order by cross sign
if(cr) return cr > 0; // CCW first
return tie(flag, s, e) < tie(l.flag, l.s, l.e); // deterministic tie-break
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
if(!(cin >> N)) return 0;
for(int i=1;i<=N;i++) cin >> A[i];
sort(A+1, A+N+1);
for(int i=1;i<=N;i++) Ord[i]=Idx[i]=i;
vector<Line> lines; lines.reserve(1LL*N*(N-1));
for(int i=1;i<=N;i++){
for(int j=i+1;j<=N;j++){
lines.emplace_back(i,j, +1);
lines.emplace_back(i,j, -1);
}
}
sort(lines.begin(), lines.end());
double mxTwice = 0.0; // store 2 * answer
for(const auto& line : lines){
if(line.flag == 1){
int a = line.i, b = line.j;
// Adjacent swap in the current labeling
swap(Idx[a], Idx[b]);
swap(Ord[Idx[a]], Ord[Idx[b]]);
int pa = Idx[line.i], pb = Idx[line.j];
if(pa > pb) swap(pa, pb);
if(pa-1 >= 1) mxTwice = max(mxTwice, dist_point_line(line.s, line.e, A[Ord[pa-1]]));
if(pb+1 <= N) mxTwice = max(mxTwice, dist_point_line(line.s, line.e, A[Ord[pb+1]]));
}else{
// Perpendicular event: (i,j) adjacent along projection → perpendicular bisector candidate
if(abs(Idx[line.i] - Idx[line.j]) == 1){
mxTwice = max(mxTwice, length(A[line.i] - A[line.j]));
}
}
}
cout.setf(ios::fixed);
cout << setprecision(10) << (mxTwice * 0.5) << '\n';
return 0;
}
|