洛谷P5735 【深基7.例1】距离函数(C语言)

时间:2024-01-26 10:15:05

 首先,三角形周长为 AB+BC+AC其次(x1,x2)和 (y1,y2)的距离

然后就可以为所欲为

#include <stdio.h>
#include <math.h>

double distance(double a1, double b1, double a2, double b2)
{
    return sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2));
}

int main()
{
    double a1, b1, a2, b2, a3, b3;
    scanf("%lf%lf%lf%lf%lf%lf", &a1, &b1, &a2, &b2, &a3, &b3);
    
    printf("%.2lf\n", distance(a1, b1, a2, b2) + distance(a1, b1, a3, b3) + distance(a2, b2, a3, b3));
    return 0;
}