第一行输入两个整数
(
),分别表示起点的横坐标和纵坐标。
第二行输入两个整数
(
),分别表示终点的横坐标和纵坐标。
输出一个实数,表示两点之间的绕距
。注意,由于浮点数存在误差,只要您的答案与标准答案之间的误差不超过
,您的答案就会被认为是正确的。
0 0 1 1
0.585786437626904951
两点间曼哈顿距离为,欧几里得距离为
,结果为
,约为
。
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x1 = sc.nextInt();
int y1 = sc.nextInt();
sc.nextLine(); // 消耗换行符\n
int x2 = sc.nextInt();
int y2 = sc.nextInt();
sc.nextLine();
int dx = x1 - x2;
int dy = y1 - y2;
double dM = Math.abs(dx) + Math.abs(dy);
double dE = Math.sqrt(dx * dx + dy * dy);
double res = Math.abs(dM - dE);
System.out.println(res);
sc.close();
}
} import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextLine()) { // 注意 while 处理多个 case
String[] a = in.nextLine().split(" ");
String[] b = in.nextLine().split(" ");
double s1 = Double.valueOf(a[0]) - Double.valueOf(b[0]);
double s2 = Double.valueOf(a[1]) - Double.valueOf(b[1]);
double dE = Math.sqrt(s1*s1 + s2*s2);
double dM = Math.abs(s1) + Math.abs(s2);
System.out.println(Math.abs(dM - dE));
}
}
} 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);
}
}