跳到正文

题解

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

cirrationaler约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年6月26日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 1 分钟
获赞
12
题目
P5735

版本

  1. v1当前

简单题。

由题目可知两点距离公式为:

dis=(x2−x1)2+(y2−y1)2dis=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}

所以,我们需要分别算出 33 条线段的长度,最后将 33 条线段的长度相加即可。

需要注意的是,由于部分答案可能是整数或一位小数,所以我们需要保留两位小数。

C++
// P5735 【深基7.例1】距离函数
// code by:cq_irritater
// time:2025/06/26
#include <bits/stdc++.h>

using namespace std;

double x1, y, x2, y2, x3, y3;
double ans1, ans2, ans3;

int main()
{
    // freopen("code.in", "r", stdin);
    cin >> x1 >> y >> x2 >> y2 >> x3 >> y3;
    ans1 = sqrt(pow((x1 - x2), 2) + pow((y - y2), 2));
    ans2 = sqrt(pow((x1 - x3), 2) + pow((y - y3), 2));
    ans3 = sqrt(pow((x3 - x2), 2) + pow((y3 - y2), 2));
    printf("%.2lf\n", ans1 + ans2 + ans3);
    return 0;
}
原文
存档评论5 条抓取于