题解:P5735 【深基7.例1】距离函数

· · 题解

这道题目只要套公式就行了,没啥好讲的,直接上代码。

#include<bits/stdc++.h>
//万能头文件 
using namespace std;
//函数 
double fun(double x1,double y1,double x2,double y2){
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));//公式 
}
int main(){
    double x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2>>x3>>y3;
    double ans1=fun(x1,y1,x2,y2);
    double ans2=fun(x2,y2,x3,y3);
    double ans3=fun(x3,y3,x1,y1);
    double c=ans1+ans2+ans3;
    printf("%.2f",c);
    return 0;
}

最后希望大家关注一下。求求了!!!!!!!