-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1111.java
More file actions
86 lines (63 loc) · 1.51 KB
/
BOJ_1111.java
File metadata and controls
86 lines (63 loc) · 1.51 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package ps;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BOJ_1111 {
static int N;
static int[] arr = new int[51];
static int[] inc = new int[51];
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) throws Exception{
input();
for(int i=0;i<N-1;i++) {
inc[i] = arr[i+1]-arr[i];
}
if(N==1) {
System.out.println("A");
return;
}
else if(N==2) {
if(arr[0] == arr[1]) {
System.out.println(arr[0]);
return;
}
else {
System.out.println("A");
return;
}
}
else {
// (y - y1) = m(x-x1)
// y = mx -m*x1 + y1
// y = mx + n
double m = ((double)inc[1]-inc[0])/((double)arr[1]-arr[0]);
int n = (int)(-m*arr[0] + inc[0]);
boolean isCorrect = true;
for(int i=0;i<N;i++) {
if(i==0)continue;
int y = (int)m*arr[i-1] + n;
if(y + arr[i-1] != arr[i]) {
isCorrect = false;
break;
}
}
if(isCorrect) {
int y = (int)m*arr[N-1] + n;
System.out.println(y+arr[N-1]);
return;
}
else {
System.out.println("B");
}
}
}
public static void input() throws Exception {
String []tmp;
N = Integer.parseInt(in.readLine());
arr = new int[51];
tmp = in.readLine().split(" ");
for(int i=0;i<N;i++) {
arr[i] = Integer.parseInt(tmp[i]);
}
}
}