求助,神奇的CE
  • 板块P5143 攀爬者
  • 楼主wzmzmhk
  • 当前回复7
  • 已保存回复7
  • 发布时间2021/7/6 09:15
  • 上次更新2023/11/4 18:34:04
查看原帖
求助,神奇的CE
250983
wzmzmhk楼主2021/7/6 09:15
#include <iostream>
#include <cmath>
#include <algorithm>
struct coorrd {
    int x, y, z;
}c[50005];
long long n;
bool sort(coorrd a, coorrd b) {
    if (a.z < b.z)
        return true;
    else
        return false;
}
double distance(coorrd a, coorrd b) {
    double X = (a.x - b.x) * (a.x - b.x);
    double Y = (a.y - b.y) * (a.y - b.y);
    double Z = (a.z - b.z) * (a.z - b.z);
    return sqrt(X + Y + Z);
}
int main() {
    double ans = 0;
    std::cin >> n;
    for (int i = 1; i <= n; i++)
        std::cin >> c[i].x >> c[i].y >> c[i].z;
    std::sort(c + 1, c + 1 + n);
    for (int i = 1; i < n; i++)
        ans += distance(c[i], c[i + 1]);
    printf("%3lf", ans);
    return 0;
}
2021/7/6 09:15
加载中...