#include <iostream>
#include <math.h>
using namespace std;
int main() {
int N;
string ansMax,ansMin,id;
double x,y,Max,Min;
cin>>N;
for(int i = 0;i<N;i++)
{
cin>>id>>x>>y;
double t = x*x + y*y;
if(i == 0)
{
Max = t;
Min = t;
ansMax = id;
ansMin = id;
}
else
{
if(t>Max)
{
Max = t;
ansMax = id;
}
if(t<Min)
{
Min = t;
ansMin = id;
}
}
}
cout<<ansMin<<" "<<ansMax<<endl;
return 0;
}
寻找最远与最近点
本文介绍了一个使用C++编程语言实现的算法,该算法通过输入一系列点的坐标,计算并输出距离原点最远和最近的点。通过计算每个点到原点的距离平方,并比较大小,最终找到最大和最小距离的点。
604

被折叠的 条评论
为什么被折叠?



