首页 技术 正文
技术 2022年11月12日
0 收藏 958 点赞 4,891 浏览 1343 个字

G – 飞花的传送门


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

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

Input

多组输入。

对于每组输入,第一行输入一个整数N(2 <= N<= 50000),接下来从第2行到第N+1行,每行两个整数(Xi,Yi),代表第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[],S[]; 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 = ;
yy = +;
for(i=;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[];
sort(P+,P+n,cmp);
S[].x = xx;
S[].y = yy;
S[] = P[];
for(i = ;i<n;)
{
if(top&&(Compare(S[top-],S[top],P[i])<)) top--;
else S[++top] = P[i++];
}
long long max1 = -;
for(i = ;i<=top;i++)
for( j = i+;j<=top;j++)
if(Dis(S[i],S[j])>max1)
max1 = Dis(S[i],S[j]);
printf("%lld\n",max1);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,090
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,567
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,415
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,187
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,824
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,907