Skip to content

Commit 0ada41d

Browse files
authored
Merge pull request #462 from AlgorithmWithGod/khj20006
[20250714] BOJ / P3 / 로버트 후드 / 권혁준
2 parents 6b70057 + 8abf2b7 commit 0ada41d

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class IOController {
6+
BufferedReader br;
7+
BufferedWriter bw;
8+
StringTokenizer st;
9+
10+
public IOController() {
11+
br = new BufferedReader(new InputStreamReader(System.in));
12+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
st = new StringTokenizer("");
14+
}
15+
16+
String nextLine() throws Exception {
17+
String line = br.readLine();
18+
st = new StringTokenizer(line);
19+
return line;
20+
}
21+
22+
String nextToken() throws Exception {
23+
while (!st.hasMoreTokens()) nextLine();
24+
return st.nextToken();
25+
}
26+
27+
int nextInt() throws Exception {
28+
return Integer.parseInt(nextToken());
29+
}
30+
31+
long nextLong() throws Exception {
32+
return Long.parseLong(nextToken());
33+
}
34+
35+
double nextDouble() throws Exception {
36+
return Double.parseDouble(nextToken());
37+
}
38+
39+
void close() throws Exception {
40+
bw.flush();
41+
bw.close();
42+
}
43+
44+
void write(String content) throws Exception {
45+
bw.write(content);
46+
}
47+
48+
}
49+
50+
class Point {
51+
int x, y;
52+
Point(int x, int y) {
53+
this.x = x;
54+
this.y = y;
55+
}
56+
57+
int ccw(Point p1, Point p2) {
58+
int res = p1.x*p2.y + p2.x*this.y + this.x*p1.y - (p2.x*p1.y + this.x*p2.y + p1.x*this.y);
59+
if(res < 0) return -1;
60+
if(res > 0) return 1;
61+
return 0;
62+
}
63+
64+
double dist(Point o) {
65+
return Math.sqrt((this.x - o.x) * (this.x - o.x) + (this.y - o.y) * (this.y - o.y));
66+
}
67+
}
68+
69+
public class Main {
70+
71+
static IOController io;
72+
73+
//
74+
75+
static int N;
76+
static Point[] a;
77+
78+
public static void main(String[] args) throws Exception {
79+
80+
io = new IOController();
81+
82+
init();
83+
solve();
84+
85+
io.close();
86+
}
87+
88+
public static void init() throws Exception {
89+
90+
N = io.nextInt();
91+
a = new Point[N];
92+
for(int i=0;i<N;i++) a[i] = new Point(io.nextInt(),io.nextInt());
93+
94+
}
95+
96+
static void solve() throws Exception {
97+
98+
// 볼록 껍질 만들기
99+
Arrays.sort(a, (a,b) -> a.x==b.x ? a.y-b.y : a.x-b.x);
100+
List<Point> lower = new ArrayList<>();
101+
List<Point> upper = new ArrayList<>();
102+
for(Point p:a) {
103+
while(lower.size() > 1 && p.ccw(lower.get(lower.size()-2), lower.get(lower.size()-1)) <= 0) lower.remove(lower.size()-1);
104+
lower.add(p);
105+
while(upper.size() > 1 && p.ccw(upper.get(upper.size()-2), upper.get(upper.size()-1)) >= 0) upper.remove(upper.size()-1);
106+
upper.add(p);
107+
}
108+
109+
List<Point> hull = new ArrayList<>();
110+
for(int i=0;i<lower.size()-1;i++) hull.add(lower.get(i));
111+
for(int i=upper.size()-1;i>0;i--) hull.add(upper.get(i));
112+
113+
114+
115+
// 회전하는 캘리퍼스 구현
116+
double ans = 0;
117+
N = hull.size();
118+
119+
int j = 1;
120+
for(int i=0;i<N;i++) {
121+
Point p1 = hull.get(i);
122+
Point p2 = hull.get((i+1)%N);
123+
Point p3 = hull.get(j);
124+
Point p4 = hull.get((j+1)%N);
125+
Point p5 = new Point(p4.x - (p3.x - p2.x), p4.y - (p3.y - p2.y));
126+
while(p5.ccw(p1, p2) > 0) {
127+
j = (j+1)%N;
128+
p3 = hull.get(j);
129+
p4 = hull.get((j+1)%N);
130+
p5 = new Point(p4.x - (p3.x - p2.x), p4.y - (p3.y - p2.y));
131+
}
132+
ans = Math.max(ans, p1.dist(p3));
133+
}
134+
io.write(ans + "\n");
135+
136+
}
137+
138+
}
139+
```

0 commit comments

Comments
 (0)