第一行输入两个整数
(
),分别表示起点的横坐标和纵坐标。
第二行输入两个整数
(
),分别表示终点的横坐标和纵坐标。
输出一个实数,表示两点之间的绕距
。注意,由于浮点数存在误差,只要您的答案与标准答案之间的误差不超过
,您的答案就会被认为是正确的。
0 0 1 1
0.585786437626904951
两点间曼哈顿距离为,欧几里得距离为
,结果为
,约为
。
/*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;
}
#include <stdio.h>
#include<math.h>
int main() {
int x1, y1, x2, y2;
scanf("%d %d", &x1, &y1);
scanf("%d %d", &x2, &y2);
float de = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2));
float dm = (x1 - x2 > 0 ? x1 - x2 : x2 - x1) + (y1 - y2 > 0 ? y1 - y2 : y2 -
y1);
printf("%.18f", de - dm > 0 ? de - dm : dm - de);
} #include <stdio.h>
#include <stdint.h>
#include <math.h>
typedef struct Point
{
float x, y;
}Point, *PPoint;
static inline float euclidean_dis_f(PPoint self_pIn, PPoint point_pIn)
{
float a = powf(self_pIn->x - point_pIn->x, 2);
float b = powf(self_pIn->y - point_pIn->y, 2);
return sqrtf(a + b);
}
static inline float abs_f(float num)
{
uint32_t* p_num = (uint32_t*)#
*p_num &= 0X7FFFFFFF;
return num;
}
static inline float manhattan_dis_f(PPoint self_pIn, PPoint point_pIn)
{
float a = self_pIn->x - point_pIn->x;
float b = self_pIn->y - point_pIn->y;
return abs_f(a) + abs_f(b);
}
int main() {
Point p1 = {.x = .0f, .y = .0f},
p2 = {.x = .0f, .y = .0f};
scanf("%f %f", &p1.x, &p1.y);
scanf("%f %f", &p2.x, &p2.y);
float result = euclidean_dis_f(&p1, &p2) - manhattan_dis_f(&p1, &p2);
printf("%f", abs_f(result));
return 0;
}