球调!球调!(回答闭关)
  • 板块题目总版
  • 楼主Machuanqi99
  • 当前回复11
  • 已保存回复13
  • 发布时间2024/8/14 17:25
  • 上次更新2024/8/14 19:59:50
查看原帖
球调!球调!(回答闭关)
1050716
Machuanqi99楼主2024/8/14 17:25
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

class Node{
	public:
		int x;
		int y;
		int z;
};
Node a[50001];

bool cmp(Node s1, Node s2){
	if(s1.z > s2.z) return false;
	return true;
}

int main(){
	int n;
	cin >> n;
	double ans = 0;
	for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y >> a[i].z;
	
	sort(a, a+n+1, cmp);
	
	for(int i = 1; i < n; i++){
		ans += 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("%.3f", ans);
	return 0;
}

有哪位大佬能报给我看看这段代码,案例过了,交上去只有三十分,将结构体中的int改为double也不行,本蒟蒻实在是搞不懂。

2024/8/14 17:25
加载中...