// hdoj_2001 计算两点间的距离
//0MS 244K 245 B GCC
#include <stdio.h>
#include <math.h>
int main(void)
{
double x1, x2, y1, y2, s;
while(scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2) != EOF)
{
s = sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
printf("%.2lf\n", s);
}
return 0;
}
一开始没注意四个数是[实数]……
本文介绍了一种计算两点间欧氏距离的算法,通过使用平方根和平方运算优化了计算过程,使得代码运行效率得到了显著提升。适用于需要频繁计算多组点间距离的应用场景。
288

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



