山东理工大学第七届ACM校赛-G 飞花的传送门

                          G - 飞花的传送门

飞花壕最近手头比较宽裕,所以想买两个传送门来代步(夏天太热,实在是懒得走路)。平面上有N个传送门,飞花壕想要挑两个距离最远的传送门带回家(距离为欧几里得距离,即两点之间直线距离)。

请你帮他算一算他所挑选的最远的两个传送门有多远。

Input

 

多组输入。

对于每组输入,第一行输入一个整数N2 <= N<= 50000),接下来从第2行到第N+1行,每行两个整数(XiYi),代表第i个传送门的坐标(-1000000 <= X, Y<= 1000000)。

数据为随机生成。

Output

 

输出一个整数,代表飞花壕要挑选的两个传送门的距离的平方。

Sample Input

4
0 0
0 1
1 1
1 0

Sample Output

2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct point
{
    long long  x;
    long long  y;
} P[50005],S[50005];

long long  xx;
long long  yy;

bool cmp(struct point a,struct point b)
{
    if(atan2(a.y-yy,a.x-xx)!=atan2(b.y-yy,b.x-xx))
        return (atan2(a.y-yy,a.x-xx))<(atan2(b.y-yy,b.x-xx));
    return a.x<b.x;
}

long long  CJ(long long  x1,long long  y1,long long  x2,long long  y2)
{
    return (x1*y2-x2*y1);
}

long long Compare(struct point a,struct point b,struct point c)
{
    return CJ((b.x-a.x),(b.y-a.y),(c.x-a.x),(c.y-a.y));
}

long long Dis(struct point a,struct point b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

int main()
{
    int n,i,j;
    while(~scanf("%d",&n))
    {
        int top = 1;
        yy = 1000000+5;
        for(i=0;i<n;i++)
        {
            scanf("%lld%lld",&P[i].x,&P[i].y);
            if(P[i].y<yy)
            {
                yy = P[i].y;
                xx = P[i].x;
                j = i;
            }
        }
        P[j] = P[0];
        sort(P+1,P+n,cmp);
        S[0].x = xx;
        S[0].y = yy;
        S[1] = P[1];
        for(i = 2;i<n;)
        {
            if(top&&(Compare(S[top-1],S[top],P[i])<0)) top--;
            else S[++top] = P[i++];
        }
        long long max1 = -1;
        for(i = 0;i<=top;i++)
            for( j = i+1;j<=top;j++)
                if(Dis(S[i],S[j])>max1)
                    max1 = Dis(S[i],S[j]);
        printf("%lld\n",max1);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值