分析:
f(x,y,a,b)+f(x,y,c,d)=sqrt(x^2+y^2+a^2+b^2-2*a*x-2*b*y)+sqrt(x^2+y^2+c^2+d^2-2*c*x-2*d*y)
=sqrt((x-a)^2+(y-b)^2)+sqrt((x-c)^2+(y-d)^2)也就是C点分别到A点B点的距离之和,因此要使最小,则C点应在AB线段上,所以最小值等于AB之间的距离。
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int t;
double a,b,c,d;
cin>>t;
while(t--)
{
cin>>a>>b>>c>>d;
printf("%.1lf\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
}
return 0;
}
原文地址:http://blog.csdn.net/a809146548/article/details/45198595