一,很自然的想法就是判断点和线段的位置关系已经点的垂点是否在线段上,然后每种情况分别计算。

  这种做法显然可行,只是觉得比较繁琐,想要更简单一点的计算方式;

二,

       向量做法,

     推荐看这篇博客https://blog.csdn.net/angelazy/article/details/38489293

      我觉说得挺好的,看了很容易理解

我自己写的代码

#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int maxn = 1000 + 10;
const ll mod = 998244353;

struct point { int x, y; };

double get_distance(point p, point A, point B) {
	point Ap, Ab, Bp;
	Ap.x = p.x - A.x, Ap.y = p.y - A.y;
	Ab.x = B.x - A.x, Ab.y = B.y - A.y;
	Bp.x = p.x - B.x, Bp.y = p.y - B.y;
	double r = (Ap.x*Ab.x + Ap.y*Ab.y)*1.0 / (Ab.x*Ab.x + Ab.y*Ab.y);

	if (r <= 0)return sqrt(Ap.x*Ap.x*1.0 + Ap.y*Ap.y);
	if (r >= 1)return sqrt(Bp.x*Bp.x*1.0+Bp.y*Bp.y);
	double px = A.x + Ab.x*r;
	double py = A.y + Ab.y*r;
	return sqrt((p.x-px)*(p.x-px)+(p.y-py)*(p.y-py));
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	

	return 0;
}