Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- struct point {
- double x, y;
- void read() {
- cin >> x >> y;
- }
- void write() {
- cout << fixed << setprecision(12) << x << ' ' << y << '\n';
- }
- point operator - (const point &B) const {
- return point{x - B.x, y - B.y};
- }
- void operator -= (const point &B) {
- x -= B.x;
- y -= B.y;
- }
- long double operator * (const point &B) const {
- return x * B.y - y * B.x;
- }
- long double orientation(const point &A, const point &B) const {
- return (A - *this) * (B - *this);
- }
- long double dist(point A) {
- A -= *this;
- return sqrt(A.x * A.x + A.y * A.y);
- }
- bool operator <(const point &A) {
- if(x == A.x) {
- return y < A.y;
- }
- return x < A.x;
- }
- };
- vector<point> buildHull(vector<point> A) {
- //
- vector<point> hull;
- for(int i = 0; i < (int) A.size(); ++i) {
- while(hull.size() >= 2) {
- int sz = hull.size();
- point P1 = hull[sz - 2];
- point P2 = hull[sz - 1];
- if(P2.orientation(P1, A[i]) < 0) {
- break;
- }
- hull.pop_back();
- }
- hull.push_back(A[i]);
- }
- return hull;
- }
- int32_t main() {
- int n;
- cin >> n;
- vector<point> points(n);
- for(int i = 0; i < n; ++i) {
- points[i].read();
- }
- sort(points.begin(), points.end());
- vector<point> upperHull = buildHull(points);
- reverse(points.begin(), points.end());
- vector<point> lowerHull = buildHull(points);
- upperHull.pop_back();
- lowerHull.pop_back();
- vector<point> polygon;
- for(point p : upperHull) {
- polygon.push_back(p);
- }
- for(point p : lowerHull) {
- polygon.push_back(p);
- }
- vector<pair<int,int>> opuse;
- int P = 0, size = polygon.size();
- for(int i = 0; i < size; ++i) {
- while(polygon[i].dist(polygon[P]) <= polygon[i].dist(polygon[(P + 1) % size]) && (P + 1) % size != i) {
- P = (P + 1) % size;
- }
- opuse.push_back(make_pair(i, P));
- }
- long double ans = 0;
- for(auto it : opuse) {
- ans = max(ans, polygon[it.first].dist(polygon[it.second]));
- }
- cout << fixed << setprecision(10) << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment