-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ04008.java
More file actions
72 lines (56 loc) · 1.7 KB
/
J04008.java
File metadata and controls
72 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//src/J04008.java
import java.util.Scanner;
public class J04008 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
Point x = new Point(sc.nextDouble(), sc.nextDouble());
Point y = new Point(sc.nextDouble(), sc.nextDouble());
Point z = new Point(sc.nextDouble(), sc.nextDouble());
double d1 = x.distance(y);
double d2 = x.distance(z);
double d3 = y.distance(z);
if (d1 <= 0 || d2 <= 0 || d3 <= 0 || d1 + d2 <= d3 || d1 + d3 <= d2 || d2 + d3 <= d1) {
System.out.println("INVALID");
} else {
System.out.printf("%.3f", d1 + d2 + d3);
System.out.println("");
}
}
}
}
//src/Point.java
class Point {
private double x;
private double y;
public Point() {
}
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public Point(Point p) {
this.x = p.x;
this.y = p.y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double distance(Point p) {
double tmp1 = Math.pow(this.x - p.x, 2);
double tmp2 = Math.pow(this.y - p.y, 2);
return Math.sqrt(tmp1 + tmp2);
}
public static double distance(Point p1, Point p2) {
double tmp1 = Math.pow(p1.x - p2.x, 2);
double tmp2 = Math.pow(p1.y - p2.y, 2);
return Math.sqrt(tmp1 + tmp2);
}
public String toString() {
return this.x + " " + this.y;
}
}