为什么能过测试,但0分啊,晕晕晕
  • 板块P5143 攀爬者
  • 楼主TiAm0
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/8 20:59
  • 上次更新2023/11/3 05:06:29
查看原帖
为什么能过测试,但0分啊,晕晕晕
1005994
TiAm0楼主2023/8/8 20:59
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
class height {
public:

    height(double x, double y, double z) {
        this->x = x;
        this->y = y;
        this->z = z;
    }
    double x, y, z;
};
bool mysort(height h1, height h2) {
    return h1.y < h2.y;
}
int main() {
    double n, x, y, z;
    double s = 0;
    vector<height>cont;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x >> y >> z;
        height h(x, y, z);
        cont.push_back(h);
    }
    sort(cont.begin(), cont.end(), mysort);
    double x1, y1, z1;
    height* itt = &cont[0];
    for (vector<height>::iterator it = ++cont.begin(); it != cont.end(); it++,itt++) {
        x1 = pow(it->x - itt->x, 2);
        y1 = pow(it->y - itt->y, 2);
        z1 = pow(it->z - itt->z, 2);
        s += pow(x1 + y1 + z1, 0.5);
    }
    printf("%.3lf", s);
}
2023/8/8 20:59
加载中...