2187

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<string>
 4 #include<vector>
 5 #include<map>
 6 #include<set>
 7 #include<cstring>
 8 #include<cstdio>
 9 #include<cmath>
10 #include<cstdlib>
11 #include<stack>
12 #include<iomanip>
13 #include<cctype>
14 #include<climits>
15 #include<queue>
16 using namespace std;
17 typedef long long ll;
18 typedef unsigned long long ull;
19 
20 struct P
21 {
22     int x,y;
23 };
24 
25 const int maxn=50010;
26 int n,k;
27 P ps[maxn];
28 
29 
30 bool cmp_x(const P& p,const P& q)
31 {
32     if(p.x!=q.x)
33         return p.x<q.x;
34     return p.y<q.y;
35 }
36 
37 int det(P p0,P p1,P p2)
38 {
39     return (p2.x-p0.x)*(p1.y-p0.y)-(p1.x-p0.x)*(p2.y-p0.y);
40 }
41 
42 vector<P> convex_hull(P* ps,int n)
43 {
44     sort(ps,ps+n,cmp_x);
45     k=0;
46     vector<P> qs(n*2);
47     for(int i=0;i<n;i++){
48         while(k>1 && det(qs[k-2],qs[k-1],ps[i])<=0)
49             k--;
50         qs[k++]=ps[i];
51     }
52      for(int i=n-2,t=k;i>=0;i--){
53          while(k>t && det(qs[k-2],qs[k-1],ps[i])<=0)
54              k--;
55         qs[k++]=ps[i];
56      }
57      qs.resize(k-1);
58      return qs;
59 }
60 
61 double dist(P p,P q)
62 {
63     return (p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y);
64 }
65 
66 int main()
67 {
68     scanf("%d",&n);
69     for(int i=0;i<n;i++)
70         scanf("%d %d",&ps[i].x,&ps[i].y);
71     vector<P> qs=convex_hull(ps,n);
72     double res;
73     for(int i=0;i<k;i++)
74         for(int j=0;j<i;j++)
75             res=max(res,dist(qs[i],qs[j]));
76     printf("%.0f
",res);
77     return 0;
78 }
做题笔记,只是想积累看看四年之后写了AC了多少题。
原文地址:https://www.cnblogs.com/ooozy/p/6273310.html