http://poj.org/problem?id=2187

12 篇文章 0 订阅
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include<iostream>
using namespace std;
#define N 50005
const double Pi = acos(-1.0);
struct Point
{
    int x,y;
}P[N],S[N];
int n,top,L;
int Dis(const Point& p1,const Point& p2)
{
    return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) ;
}
double Cross(const Point& p1,const Point& p2,const Point& p3,const Point& p4)
{
    return (p2.x-p1.x)*(p4.y-p3.y) - (p2.y-p1.y)*(p4.x-p3.x);
}
bool cmp(const Point& p1,const Point& p2)
{
    double C = Cross(P[0],p1,P[0],p2);
    return C ? C>0 : Dis(P[0],p1)>Dis(P[0],p2);
}
bool Cmp(Point x,Point y)
{
  if(x.x!=y.x)
   {
	  return x.x<y.x;
   }
  else if(x.x==y.x)
   {
 	  return x.y<y.y;
   }
}
void Pole_Point()
{
    int id;
    Point pp = P[id=0];
    for(int i=1;i<n;i++)
        if(P[i].y < pp.y || P[i].y == pp.y && P[i].x < pp.x)
            pp = P[i] , id = i;
    P[id] = P[0] , P[0] = pp;
}
void Convex_Hull()
{
    Pole_Point();
    sort(P+1,P+n,cmp);
    S[0]=P[0],S[1]=P[1],S[top=2]=P[2];
    for(int i=3;i<n;i++)
    {
        while(top>0&&Cross(S[top-1],S[top],S[top],P[i]) < 0)
            --top;
        S[++top] = P[i];
    }
}
int main(){	
	 
    scanf("%d",&n);
		
	     for(int i=0;i<n;i++)
            scanf("%d%d",&P[i].x,&P[i].y);
           Convex_Hull();
        int ans =-99;
         // S[top+1] = S[0];
      for(int i=0;i<=top;++i)
		  for(int j=i+1;j<=top;j++)
		  {
		    if(Dis(S[i],S[j])>ans)
				ans=Dis(S[i],S[j]);
		  }
		 printf("%d\n",ans);
    
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值