-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-旋转卡壳(一).cpp
73 lines (72 loc) · 1.34 KB
/
05-旋转卡壳(一).cpp
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
//Created By sweet_fish
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-10;
const double pi=acos(-1);
struct point
{
double x,y;
point operator-(const point &t)const
{
return{x-t.x,y-t.y};
}
};
point p[100005],a[100005];
int dist2(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
bool cmp(const point &a,const point &b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int Andrew(int n)
{
sort(p,p+n,cmp);
int sz=0;
for(int i=0;i<n;++i)
{
while(sz>1&&cross(p[i]-a[sz-2],p[i]-a[sz-1])<=eps)
--sz;
a[sz++]=p[i];
}
int tp=sz;
for(int i=n-2;i>=0;--i)
{
while(sz>tp&&cross(p[i]-a[sz-2],p[i]-a[sz-1])<=eps)
--sz;
a[sz++]=p[i];
}
return --sz;
}
int rot(int n)
{
a[n+1]=a[0];
int ans=0;
int j=2;
for(int i=0;i<n;++i)
{
while(cross(a[i+1]-a[i],a[j]-a[i])<cross(a[i+1]-a[i],a[j+1]-a[i]))
j=(j+1)%n;
ans=max(ans,dist2(a[j],a[i]));
ans=max(ans,dist2(a[j],a[i+1]));
}
return ans;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;++i)
scanf("%lf%lf",&p[i].x,&p[i].y);
int sz=Andrew(n);
printf("%d\n",rot(sz));
}
}