[2020.10.28 SSL Simulation Tournament T1] [Luogu P1452] MSWORLD [Mathematics (Metaphysics)]

Title description

Problem
Given n points on a plane, find the diameter of the convex hull.

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

analysis:

Approximately O (n 2) O(n^2)O ( n2 )Complexity +a bunch of metaphysical operationsLuogu has ever been on the Purple Question?
The Pythagorean Theoremviolently seeks the maximum distance to limit the operation

CODE:

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll n,x[50005],y[50005],ans;
int main(){
    
    
	scanf("%lld",&n);
	if(n==1)
	{
    
    
		printf("-1"); 
		return 0;  //数据问题
	}
	n=min(48000ll,n);  //玄学
	for(register int i=1;i<=n;i++)
	{
    
    
		scanf("%lld%lld",&x[i],&y[i]);
		for(register int j=1;j<i;j++)
			ans=max(ans,(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));  //勾股求距离
	}
	printf("%lld",ans);
	
	return 0;
} 

Guess you like

Origin blog.csdn.net/dgssl_xhy/article/details/109337337