洛谷-P5735 【深基7.例1】距离函数

洛谷-P5735 【深基7.例1】距离函数

原题链接:https://www.luogu.com.cn/problem/P5735


题目描述

给出平面坐标上不在一条直线上三个点坐标 \((x_1,y_1),(x_2,y_2),(x_3,y_3)\),坐标值是实数,且的绝对值不超过 100.00,求围成的三角形周长。保留两位小数。

对于平面上的两个点 \((x_1,y_1),(x_2,y_2)\),则这两个点之间的距离 \(dis=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}\)

输入格式

输出格式

输入输出样例

输入 #1

0 0 0 3 4 0

输出 #1

12.00

C++代码

#include <cstdio>
#include <cmath>
using namespace std;

double dis(double x1, double x2, double y1, double y2) {
    return sqrt(pow(x2-x1, 2) + pow(y2-y1, 2));
}

int main() {
    double x1, x2, x3, y1, y2, y3, ans;
    scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
    ans = dis(x1, x2, y1, y2) + dis(x1, x3, y1, y3) + dis(x2, x3, y2, y3);
    printf("%.2f\n", ans);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/yuzec/p/13394949.html