Skip to content

Commit 8d05ac7

Browse files
authored
[20250613] BOJ / P3 / 쓰레기 슈트 / 권혁준
1 parent f90693e commit 8d05ac7

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
double x, y;
52+
Point(double x, double y) {
53+
this.x = x;
54+
this.y = y;
55+
}
56+
}
57+
58+
public class Main {
59+
60+
static IOController io;
61+
62+
//
63+
64+
static int N;
65+
static Point[] A;
66+
static List<Point> H;
67+
68+
public static void main(String[] args) throws Exception {
69+
70+
io = new IOController();
71+
72+
N = io.nextInt();
73+
for(int t=1;N != 0;t++) {
74+
init();
75+
solve(t);
76+
N = io.nextInt();
77+
}
78+
79+
io.close();
80+
81+
}
82+
83+
public static void init() throws Exception {
84+
85+
A = new Point[N];
86+
for(int i=0;i<N;i++) A[i] = new Point(io.nextInt(), io.nextInt());
87+
H = new ArrayList<>();
88+
89+
}
90+
91+
static void solve(int tc) throws Exception {
92+
93+
construct();
94+
double ans = 1e9;
95+
for(int i=0;i<H.size();i++) {
96+
Point a = H.get(i), b = H.get((i+1)%H.size());
97+
double res = 0;
98+
for(int j=0;j<H.size();j++) if(j != i && j != (i+1)%H.size()){
99+
Point c = H.get(j);
100+
res = Math.max(res, get(a, b, c));
101+
}
102+
ans = Math.min(ans, res);
103+
}
104+
105+
int answer = (int)Math.ceil(ans * 100 - 1e-15);
106+
107+
String p1 = Integer.toString(answer/100);
108+
String p2 = Integer.toString(answer%100);
109+
if(p2.length() == 1) p2 = "0" + p2;
110+
111+
io.write("Case " + tc + ": " + p1 + "." + p2 + "\n");
112+
113+
}
114+
115+
static void construct() throws Exception {
116+
117+
Arrays.sort(A, (a,b) -> {
118+
if(a.x == b.x) return Double.compare(a.y,b.y);
119+
return Double.compare(a.x,b.x);
120+
});
121+
122+
List<Point> lower = new ArrayList<>();
123+
List<Point> upper = new ArrayList<>();
124+
for(int i=0;i<N;i++) {
125+
Point p = A[i];
126+
while(lower.size()>1 && ccw(lower.get(lower.size()-2), lower.get(lower.size()-1), p) <= 0) lower.remove(lower.size()-1);
127+
lower.add(p);
128+
}
129+
for(int i=0;i<N;i++) {
130+
Point p = A[i];
131+
while(upper.size()>1 && ccw(upper.get(upper.size()-2), upper.get(upper.size()-1), p) >= 0) upper.remove(upper.size()-1);
132+
upper.add(p);
133+
}
134+
135+
for(int i=0;i<lower.size()-1;i++) H.add(lower.get(i));
136+
for(int i=upper.size()-1;i>0;i--) H.add(upper.get(i));
137+
138+
}
139+
140+
static int ccw(Point a, Point b, Point c) {
141+
double res = a.x*b.y + b.x*c.y + c.x*a.y - (b.x*a.y + c.x*b.y + a.x*c.y);
142+
if(res > 0) return 1;
143+
if(res < 0) return -1;
144+
return 0;
145+
}
146+
147+
static double get(Point a, Point b, Point c) {
148+
149+
double dx = b.x-a.x, dy = b.y-a.y;
150+
151+
// y = dy/dx (x - a.x) + a.y
152+
// dx*y = dy*x - dy*a.x + dx*a.y
153+
// dy*x - dx*y - dy*a.x + dx*a.y = 0
154+
155+
double ans = Math.abs(dy*c.x - dx*c.y + a.y*dx - a.x*dy) / Math.sqrt(dy*dy + dx*dx);
156+
return ans;
157+
158+
}
159+
160+
}
161+
```

0 commit comments

Comments
 (0)