We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 490bde4 commit 61556b2Copy full SHA for 61556b2
1 file changed
src/src/codingTest/Data_Structure/막대기/Main.java
@@ -0,0 +1,34 @@
1
+package codingTest.Data_Structure.막대기;
2
+
3
+import java.util.ArrayList;
4
+import java.util.PriorityQueue;
5
+import java.util.Scanner;
6
7
+public class Main {
8
+ public static void main(String[] args) {
9
+ Scanner sc = new Scanner(System.in);
10
+ int X = sc.nextInt();
11
12
+ PriorityQueue<Integer> pq = new PriorityQueue<>();
13
+ pq.add(64);
14
15
+ while (sum(pq) > X) {
16
+ Integer shortBar = pq.poll();
17
+ int halfBar = shortBar >> 1;
18
+ pq.add(halfBar);
19
+ if (sum(pq) < X) {
20
21
+ }
22
23
+ System.out.println(pq.size());
24
25
26
27
+ public static int sum(PriorityQueue<Integer> pq) {
28
+ int sum = 0;
29
+ for (Integer integer : pq) {
30
+ sum += integer;
31
32
+ return sum;
33
34
+}
0 commit comments