-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlog Photo
More file actions
52 lines (46 loc) · 1.63 KB
/
Blog Photo
File metadata and controls
52 lines (46 loc) · 1.63 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
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = br.readLine().split(" ");
long h = Long.parseLong(s[0]);
long w = Long.parseLong(s[1]);
long bestH = 1, bestW = 1, bestArea = 1;
for (int k = 0; k <= 31; k++) {
long p = 1L << k;
// Case 1: H = p
if (p <= h) {
long lo = (long) Math.ceil(p / 1.25);
long hi = (long) Math.floor(p / 0.8);
lo = Math.max(lo, 1);
hi = Math.min(hi, w);
if (lo <= hi) {
long W = hi;
long area = p * W;
if (area > bestArea || (area == bestArea && p > bestH)) {
bestArea = area;
bestH = p;
bestW = W;
}
}
}
// Case 2: W = p
if (p <= w) {
long lo = (long) Math.ceil(0.8 * p);
long hi = (long) Math.floor(1.25 * p);
lo = Math.max(lo, 1);
hi = Math.min(hi, h);
if (lo <= hi) {
long H = hi;
long area = H * p;
if (area > bestArea || (area == bestArea && H > bestH)) {
bestArea = area;
bestH = H;
bestW = p;
}
}
}
}
System.out.println(bestH + " " + bestW);
}
}