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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| #include <iostream> #include <algorithm> #include <cmath> #include <cstdio>
using namespace std;
const int MAX = 200005; const double eps = 1e-7;
struct Point { double x, y;
Point operator+(const Point &b) const { return {x + b.x, y + b.y}; }
Point operator-(const Point &b) const { return {x - b.x, y - b.y}; }
double operator^(const Point &b) const { return x * b.y - y * b.x; }
bool operator<(const Point &b) const { if (x != b.x) return x < b.x; return y < b.y; } };
Point p[MAX]; Point s[MAX]; int top;
void selMin(int n); int cmp(Point a, Point b); bool equal(double a, double b); double dis(Point a, Point b); void graham(int n); double s_sqr(Point a, Point b, Point c); double diameter();
int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y; selMin(n); sort(p + 1, p + n, cmp); graham(n); printf("%.6f", sqrt(diameter())) ; return 0; }
void selMin(int n) { Point Min = p[0]; int IDMin = 0; for (int i = 0; i < n; i++) if (p[i] < Min) { Min = p[i]; IDMin = i; } swap(p[0], p[IDMin]); }
int cmp(Point a, Point b) { double x = (a - p[0]) ^ (b - p[0]); if (x > 0) return 1; if (equal(x, 0) && (dis(a, p[0]) < dis(b, p[0]))) return 1; return 0; }
double dis(Point a, Point b) { double x = a.x - b.x; double y = a.y - b.y; return x * x + y * y; }
void graham(int n) { top = 1; s[0] = p[0]; s[1] = p[1]; for (int i = 2; i < n; i++) { while (top > 1 && ((p[i] - s[top]) ^ (s[top - 1] - s[top])) <= 0) top--; s[++top] = p[i]; } }
double s_sqr(Point a, Point b, Point c) { return fabs((a - b) ^ (c - b)); }
double diameter() { double diam = 0; int j = 2; s[++top] = s[0]; if (top < 3) return dis(s[0], s[1]); for (int i = 0; i < top - 1; i++) { while (s_sqr(s[i], s[i + 1], s[j]) < s_sqr(s[i], s[i + 1], s[(j + 1) % top])) j = (j + 1) % top; diam = max(diam, max(dis(s[i], s[j]), dis(s[i + 1], s[j]))); } return diam; } bool equal(double a, double b){ return fabs(a - b) < eps; }
|