#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
int N;
struct Coordinate
{
int x;
int y;
int z;
}coordinate[50000];
bool compare(const Coordinate& a, const Coordinate& b)
{
return a.z < b.z;
}
double distance(const Coordinate& a, const Coordinate& b)
{
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2) + pow(a.z - b.z, 2));
}
int main()
{
double s = 0.0, temp;
cin >> N;
for (int i = 0; i < N; i++)
cin >> coordinate[i].x >> coordinate[i].y >> coordinate[i].z;
sort(coordinate, coordinate + N, compare);
for (int i = 0; i < N - 1; i++)
s += distance(coordinate[i], coordinate[i + 1]);
cout << fixed << setprecision(3) << s;
return 0;
}
洛谷P5143 攀爬者进阶解法
最新推荐文章于 2024-07-07 22:43:15 发布