第一行输入两个整数
(
),分别表示起点的横坐标和纵坐标。
第二行输入两个整数
(
),分别表示终点的横坐标和纵坐标。
输出一个实数,表示两点之间的绕距
。注意,由于浮点数存在误差,只要您的答案与标准答案之间的误差不超过
,您的答案就会被认为是正确的。
0 0 1 1
0.585786437626904951
两点间曼哈顿距离为,欧几里得距离为
,结果为
,约为
。
#include <iostream>
using namespace std;
#include <cmath>
#include <iomanip>
int main(){
double x1,y1;
double x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
double dE = sqrt(pow(x1-x2,2) + pow(y1-y2,2));
double dM = std::abs(x1-x2) + std::abs(y1-y2);
double c = std::abs(dE - dM);
cout << fixed << setprecision(18);
cout << c << endl;
return 0;
} from decimal import Decimal, getcontext
getcontext().prec=50
x1,y1=map(int,input().split())
x2,y2=map(int,input().split())
dx=abs(x1-x2)
dy=abs(y1-y2)
dm=Decimal(f"{dx+dy}")
de=Decimal(f"{dx**2+dy**2}")**Decimal('0.5')
dd=f"{abs(dm-de)}"
if '.' in dd:
l,r=dd.split('.')
result=f"{l}.{r[:18].ljust(18,'0')}"
else:
result=f"{dd}.{'0'*18}"
print(result) /*2025年10月12日00:49:03
输出一个实数,表示两点之间的绕距
Δ
Δ。注意,由于浮点数存在误差,只要您的答案与标准答案之间的误差不超过10−6,您的答案就会被认为是正确的。*/
# include <stdio.h>
# include <math.h>//包含数学函数的头文件
int main()
{
int x1, y1, x2, y2;
double dE, dM, data;
scanf("%d %d\n", &x1, &y1);
scanf("%d %d", &x2, &y2);
dE = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
//pow() 是 C 标准库 <math.h> 中的一个函数,用于计算一个数的幂。
// 具体来说,它返回的是第一个参数的第二个参数次幂,即 x^ y。
dM = (abs(x1 - x2) + abs(y1 - y2));
//C 库函数 int abs(int x) 返回整数 x 的绝对值。
//注意:abs() 函数只适用于整数,如果需要计算浮点数的绝对值,需要使用 fabs() 函数。
data = fabs(dM - dE);
//C 库函数 double fabs(double x) 返回浮点数 x 的绝对值。
//fabs() 是 C 标准库 <math.h> 中的一个函数,用于计算一个数的绝对值。这个函数在处理数***算时非常有用,可以确保获得数值的非负表示。
//注意:fabs() 函数可以用于 double、float 和 long double 类型的参数。如果需要计算整数的绝对值,应该使用 abs() 函数。
printf("%.18f", data);
return 0;
}
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String city1 = in.nextLine();
String city2 = in.nextLine();
String [] ab = city1.split(" ");
String [] cd = city2.split(" ");
double x = Math.abs(Integer.valueOf(ab[0])-Integer.valueOf(cd[0]));
double y = Math.abs(Integer.valueOf(ab[1])-Integer.valueOf(cd[1]));
double E = Math.sqrt(x*x+y*y);
double M = x + y ;
double z = Math.abs(M - E);
System.out.println(z);
}
} #include <stdio.h>
#include <math.h>
int main() {
int x1 = 0;
int y1 = 0;
scanf("%d %d", &x1, &y1);
int x2 = 0;
int y2 = 0;
scanf("%d %d", &x2, &y2);
long double dx = x1 - x2;
long double dy = y1 - y2;
long double E = sqrtl(dx * dx + dy * dy);
long double M = fabsl(dx) + fabsl(dy);
long double R = fabsl(M - E);
printf("%.18Lf\n", R);
return 0;
}