求直径,很裸,,随便搞搞就好。。
1 #include<cstdio> 2 #include<algorithm> 3 #include<cmath> 4 #define eps 1e-8 5 using namespace std; 6 int n,top; 7 double ans; 8 struct point{ 9 double x,y; 10 point(){} 11 point (double _x, double _y): x(_x),y(_y){} 12 friend point operator + (point a, point b){ 13 return point(a.x+b.x, a.y+b.y); 14 } 15 friend point operator - (point a, point b){ 16 return point (a.x-b.x,a.y-b.y); 17 } 18 friend point operator * (point a, double b){ 19 return point (a.x*b,a.y*b); 20 } 21 friend double operator * (point a, point b){ 22 return a.x*b.y-a.y*b.x; 23 } 24 friend double operator / (point a, point b){ 25 return a.x*b.x+a.y*b.y; 26 } 27 friend bool operator == (point a, point b){ 28 return fabs(a.x-b.x)<eps && fabs(a.y-b.y)<eps; 29 } 30 friend bool operator !=(point a, point b){ 31 return !(a==b); 32 } 33 friend bool operator < (point a, point b){ 34 return a.y==b.y?a.x<b.x:a.y<b.y; 35 } 36 friend double dis(point a){ 37 return sqrt(a.x*a.x+a.y*a.y); 38 } 39 void print(){ 40 printf("%lf %lf ",x,y); 41 } 42 }p[50005],st[50005]; 43 bool cmp(point a, point b){ 44 double t=(a-p[1])*(b-p[1]); 45 if (fabs(t)<eps) return dis(p[1]-a)-dis(p[1]-b)<0; 46 return t>0; 47 } 48 void Graham() 49 { 50 for (int i=2; i<=n; i++) 51 if (p[i]<p[1]) swap(p[1],p[i]); 52 sort(p+2,p+n+1,cmp); 53 st[++top]=p[1]; 54 for (int i=2; i<=n; i++) 55 { 56 while (top>1 && (p[i]-st[top])*(st[top]-st[top-1])>=0) top--; 57 st[++top]=p[i]; 58 } 59 st[0]=st[top]; 60 } 61 void RC() 62 { 63 int pos=2; 64 for (int i=1; i<=top; i++) 65 { 66 while ((pos+1)%top!=i && (st[i+1]-st[i])*(st[pos+1]-st[i])>(st[i+1]-st[i])*(st[pos]-st[i])) pos=(pos+1)%top; 67 ans=max(ans,dis(st[pos]-st[i])); 68 // printf("%lf ",ans); 69 // while (1); 70 } 71 } 72 int main() 73 { 74 scanf("%d",&n); 75 for (int i=1; i<=n; i++) scanf("%lf%lf",&p[i].x,&p[i].y); 76 Graham(); RC(); 77 printf("%d",(int)((ans*ans+0.1))); 78 return 0; 79 }