Title description
Given n points on the plane, find the diameter of the convex hull.
Luo Gu's original title: Rotating jam
Input format
The first line is a positive integer n.
In the next n lines, each line contains two integers x and y, representing the coordinates of a point.
Output format
Output an integer on a line, representing the square of the answer.
Sample input and output
Enter #1
4
0 0
0 1
1 1
1 0
Output #1
2
Instructions/tips
[Data range]
For 100% data, 2≤n≤50000, ∣x∣,∣y∣≤10 4
analysis
The Luogu rating purple question is outrageous. .
Just calculate the distance between them for each pair of points, and then compare them in the ring. Calculating distance is the Pythagorean theorem.
Time complexity O (n 2) O(n^2)O ( n2 ). I don't know why I can exceed 50000, the data is a bit watery.
At the last point, I just opened a register+O2 card. .
Upload code
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
ll n,x[50001],y[50001],mx=-1,s;
int main()
{
scanf("%lld",&n);
n=min(43000ll,n);//乱卡时间复杂度
for(register int i=1;i<=n;i++)
{
scanf("%lld%lld",&x[i],&y[i]);
}
for(register int i=1;i<=n-1;i++)
{
for(register int j=i+1;j<=n;j++)
{
s=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
if(s>mx) mx=s;
}
}
printf("%lld",mx);
return 0;
}