Problem B: 点之间的距离

时间:2023-03-09 04:23:43
Problem B: 点之间的距离
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
class Point
{
public:
    double x,y;
    Point(double a=0,double b=0):x(a),y(b){}
    Point set(double a,double b)
    {
        x=a;
        y=b;
        return *this;
    }
    friend double operator -(Point &q,Point &p)
    {
        double t=sqrt(pow(fabs(q.x-p.x),2)+pow(fabs(q.y-p.y),2));
        return t;
    }
};
class PointArray:public Point
{
public:
    vector<Point> s;
    void append(Point p)
    {
        s.push_back(p);
    }
    double getMaxDis()
    {
        int n=s.size();
        double maxdis=0;
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                maxdis=max(maxdis,s[i]-s[j]);

        return maxdis;
    }

};
int main()
{
    Point p, p1(10, 10), p2(20, 20);
    PointArray pArr;
    double x, y;
    while(cin>>x>>y)
    {
        p.set(x, y);
        pArr.append(p);
    }
    cout<<p2 - p1<<endl;
    cout<<pArr.getMaxDis()<<endl;
    return 0;
}