跳到正文

题解

题解:P5735 【深基7.例1】距离函数

zpx111223约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年6月28日
收录
2025年12月12日
更新
2026年11月8日
篇幅
约 1 分钟
题目
P5735

版本

  1. v1当前

原题链接

LinkLink

数学公式

两点之间的距离=

(x2−x1)2+(y2−y1)2\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}

知道了公式,就可以写下代码辣

code

知道你们最喜欢

C++
#include<bits/stdc++.h>
#define int double
using namespace std;
int func(int x1,int y1,int x2,int y2){
	return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));//公式
}
int ans;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x1,y1,x2,y2,x3,y3;
	cin>>x1>>y1>>x2>>y2>>x3>>y3;
	ans+=func(x1,y1,x2,y2);
	ans+=func(x1,y1,x3,y3);
	ans+=func(x2,y2,x3,y3);
	printf("%.2lf",ans);//保留两位小数
	return 0;
}

4年级小学生蒟蒻第一次写题解,管理员大大球过

原文