[Link] https://AtCoder.jp/contests/typical90/tasks/typical90_i
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
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int n = Integer.parseInt(reader.readLine());
double min = Double.MAX_VALUE;
int[][] p = new int[n][2];
for(int i = 0; i < n; i++) {
st = new StringTokenizer(reader.readLine());
p[i][0] = Integer.parseInt(st.nextToken());
p[i][1] = Integer.parseInt(st.nextToken());
}
for(int i = 0 ; i < n ; i++) {
double[] sort = new double[n - 1]; // n-1
int idx = 0;
for(int j = 0; j < n; j++) {
if(i == j) continue;
sort[idx++] = getAngle(p[i], p[j]);
getAngle(p[i], p[j]);
}
Arrays.sort(sort);
for(int k = 0; k < n - 1; k++) {
double toFind = (180 + sort[k]) % 360;
int l = 0, r = n-2, mid;
while(l < r) {
mid = (l + r) / 2;
if(l == r - 1) {
double smaller = Math.min(Math.abs(sort[l] - toFind), Math.abs(sort[r] - toFind));
min = Math.min(smaller, min);
break;
}
if(sort[mid] < toFind) l = mid;
else if(sort[mid] == toFind) {
min = 0;
break;
} else r = mid;
}
}
}
if(min == Double.valueOf((int)min)) System.out.println(180 - (int)min);
else System.out.println(180 - min);
}
static double getAngle(int[] zeroP, int[] p) {
int dx, dy;
dx = p[0] - zeroP[0];
dy = p[1] - zeroP[1];
double theta = Math.atan2(dy, dx);
return theta >= 0 ? theta : (360 + theta);
}
// static double getAngle(int[] zeroP, int[] p) {
// long dx, dy;
// dx = p[0] - zeroP[0];
// dy = p[1] - zeroP[1];
// double theta = Math.acos((double)dx / Math.sqrt(dx*dx + dy*dy)) * 180 / Math.PI;
// return dy >= 0 ? theta : (360 - theta);
// }
}