P5143 攀爬者

题目传送门

#include <bits/stdc++.h>

using namespace std;
const int N = 50010;
struct Point {
    int x, y, z;
} a[N];

bool cmp(const Point &a, const Point &b) {
    return a.z > b.z;
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i].x >> a[i].y >> a[i].z;
    sort(a + 1, a + 1 + n, cmp);
    double s = 0;
    for (int i = 2; i <= n; i++)
        s += sqrt(pow(a[i].x - a[i - 1].x, 2) + pow(a[i].y - a[i - 1].y, 2) + pow(a[i].z - a[i - 1].z, 2));

    printf("%.3lf", s);
    return 0;
}
上一篇:python学习之 —— 条件和循环


下一篇:C语言面试基础