-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_7869.java
More file actions
55 lines (34 loc) · 1.69 KB
/
baekjoon_7869.java
File metadata and controls
55 lines (34 loc) · 1.69 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
import java.util.*;
import java.io.*;
public class baekjoon_7869 {
private static int CROSS = 0;
private static int NOT_CROSS = 1;
private static int INNER = 2;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
Double x1, x2, y1, y2, r1, r2;
x1 = Double.parseDouble(st.nextToken());
y1 = Double.parseDouble(st.nextToken());
r1 = Double.parseDouble(st.nextToken());
x2 = Double.parseDouble(st.nextToken());
y2 = Double.parseDouble(st.nextToken());
r2 = Double.parseDouble(st.nextToken());
Double dist = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
if(r1 + r2 <= dist){
System.out.println("0.000");
}
else if(dist <= (Math.max(r1, r2) - Math.min(r1, r2))) {
System.out.printf("%.3f", (Math.pow(Math.min(r1, r2), 2) * Math.PI));
}
else{
Double cosTheta1 = (Math.pow(r1, 2) + Math.pow(dist, 2) - Math.pow(r2, 2)) / (2.0 * r1 * dist);
Double cosTheta2 = (Math.pow(r2, 2) + Math.pow(dist, 2) - Math.pow(r1, 2)) / (2.0 * r2 * dist);
Double theta1 = Math.acos(cosTheta1) * 2.0;
Double theta2 = Math.acos(cosTheta2) * 2.0;
Double sumOfSector = (Math.pow(r1, 2) * theta1)/2.0 + (Math.pow(r2, 2) * theta2)/2.0;
Double sumOfTri = (Math.pow(r1, 2) * Math.sin(theta1)) / 2.0 + (Math.pow(r2, 2) * Math.sin(theta2)) / 2.0;
System.out.printf("%.3f", sumOfSector - sumOfTri);
}
}
}