poj2187 Beauty Contest

传送门

求平面上距离最远的两个点距离的平方。

凸包,旋转卡壳。

抄板选手的日常。

 

 1 //Achen
 2 #include<algorithm>
 3 #include<iostream>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<vector>
 7 #include<cstdio>
 8 #include<queue>
 9 #include<cmath>
10 typedef long long LL;
11 typedef double db;
12 const db eps=1e-10;
13 const int N=50007;
14 using namespace std;
15 int n;
16 
17 template<typename T>void read(T &x)  {
18     char ch=getchar(); x=0; T f=1;
19     while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
20     if(ch=='-') f=-1,ch=getchar();
21     for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
22 }
23 
24 struct pt {
25     db x,y;
26     pt(db x=0,db y=0):x(x),y(y){} 
27 }p[N],q[N]; 
28 typedef  pt vc; 
29 
30 vc operator + (vc A,vc B) { return vc(A.x+B.x,A.y+B.y);}
31 vc operator - (vc A,vc B) { return vc(A.x-B.x,A.y-B.y);}
32 bool operator <(const vc&A,const vc&B) { return A.x<B.x||(A.x==B.x&&A.y<B.y);}
33 int dcmp(double x) { if(fabs(x)<eps) return 0; else return x<0?-1:1;}
34 bool operator == (const vc&A,const vc&B) { return dcmp(A.x-B.x)==0&&dcmp(A.y-B.y)==0; }
35 
36 db dot(vc A,vc B) { return A.x*B.x+A.y*B.y; }
37 db length(vc A) { return dot(A,A); }
38 db cross(vc A,vc B) { return A.x*B.y-A.y*B.x; }
39 
40 bool cmp(const pt &A,const pt&B) {
41     return dcmp(cross(A-p[1],B-p[1]))==0?length(A-p[1])<length(B-p[1]):cross(A-p[1],B-p[1])>0;
42 }
43 
44 int top;
45 void graham() {
46     for(int i=2;i<=n;i++) if(p[i]<p[1]) swap(p[i],p[1]);
47     sort(p+2,p+n+1,cmp);
48     q[++top]=p[1]; q[++top]=p[2];
49     for(int i=3;i<=n;i++) {
50         while(top>1&&cross(q[top]-q[top-1],p[i]-q[top-1])<eps) top--;
51         q[++top]=p[i];
52     }
53 }
54 
55 db RC() {
56     q[top+1]=q[1];
57     int now=2; 
58     db res=0;
59     for(int i=1;i<=top;i++) {
60         while(cross(q[i+1]-q[i],q[now]-q[i])<cross(q[i+1]-q[i],q[now+1]-q[i])) {
61             now++; if(now==top+1) now=1;
62         }    
63         res=max(res,length(q[now]-q[i]));
64     }
65     return res;
66 }
67 
68 int main() {
69     read(n);
70     for(int i=1;i<=n;i++) { read(p[i].x); read(p[i].y); }
71     graham();
72     printf("%d\n",(int)RC());
73     return 0;
74 }
View Code

 

posted @ 2018-02-23 13:21  啊宸  阅读(150)  评论(0编辑  收藏  举报