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
| #include <bits/stdc++.h> #define Orz ios::sync_with_stdio(0),cin.tie(0) #define rep(i,a,b) for(int i=a;i<=b;i++) #define pii pair<int,int> #define pdd pair<double,double> #define int long long #define ll long long #define ld long double #define N 100001 #define eps 1e-9 #define x first #define y second
using namespace std;
struct pt{ ld x,y; bool operator < (pt b){ if(x == b.x)return y < b.y; return x < b.x; } bool operator > (pt b){ if(x == b.x)return y > b.y; return x > b.x; } bool operator == (pt b){ if(abs(x-b.x)<=eps && abs(y-b.y)<=eps)return true; return false; } pt operator+(pt b) {return {x + b.x, y + b.y};} pt operator-(pt b) {return {x - b.x, y - b.y};} ld operator^(pt b) {return x * b.y - y * b.x;} ld operator*(pt b) {return x * b.x + y * b.y;} }; bool cmp(pt a, pt b){ if(a.x == b.x)return a.y < b.y; return a.x < b.x; } vector<pt> p,hull; int n,t,h; ld ans;
bool check(pt a,pt b,pt o){ int cross = (a - o)^(b - o); return cross >= 0; }
bool check2(pt a,pt b,pt c,pt d){ ld aa = (a - c)^(b - c); ld bb = (a - d)^(b - d); return aa < bb; }
ld area(pt a,pt b){ return abs(a^b)/2; }
void convex_hull(){ hull.clear(); sort(p.begin(),p.end(),cmp); for(auto i : p){ while(hull.size()>=2 && check(i,hull[hull.size()-1],hull[hull.size()-2])){ hull.pop_back(); } hull.push_back(i); } int down_hull = hull.size(); h = down_hull-1; hull.pop_back(); reverse(p.begin(),p.end()); for(auto i: p){ while(hull.size() > down_hull && check(i,hull[hull.size()-1],hull[hull.size()-2])){ hull.pop_back(); } hull.push_back(i); } hull.pop_back(); }
void solve(){ int d,sz = hull.size(); rep(i,0,sz-1){ rep(j,i+1,sz-1){ d = (j+1)%sz; while(check2(hull[i],hull[(j)%sz],hull[d],hull[(d+1)%sz])) d = (d+1)%sz; ans = max(ans,area((hull[d]-hull[i]),(hull[d]-hull[j]))); } } }
signed main(){ Orz; cin>>n; p.assign(n,{0,0}); rep(i,0,n-1)cin>>p[i].x>>p[i].y; convex_hull(); ans = 0; solve(); cout<<fixed<<setprecision(6); cout<<ans<<endl; }
|