P5143 攀爬者

// Problem: P5143 攀爬者
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P5143
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn

#include <bits/stdc++.h>

using namespace std;

struct Point {
    int x;
    int y;
    int z;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<Point> info(n);
    for (int i = 0; i < n; ++i) {
        cin >> info[i].x >> info[i].y >> info[i].z;
    }
    
    sort(info.begin(), info.end(), [](const Point &p1, const Point &p2) -> bool {
        return p1.z < p2.z;
    });
    
    double res = 0;
    for (int i = 1; i < n; ++i) {
        res += sqrt(pow(info[i].x - info[i - 1].x, 2) +
            pow(info[i].y - info[i - 1].y, 2) + pow(info[i].z - info[i - 1].z, 2));
    }
    printf("%.3f\n", res);
    return 0;
}
posted @ 2022-01-29 15:15  Pannnn  阅读(46)  评论(0)    收藏  举报
-->