Skip to content

Commit a0f1055

Browse files
committed
0929
1 parent 6f873ca commit a0f1055

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BOJ/silver/BOJ16953/BOJ16953.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

BOJ/silver/BOJ16953/src/Main.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.BufferedReader;
2+
import java.io.IOException;
3+
import java.io.InputStreamReader;
4+
import java.util.*;
5+
6+
public class Main {
7+
static int minV= Integer.MAX_VALUE;
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
10+
StringTokenizer st =new StringTokenizer(br.readLine());
11+
long N = Integer.parseInt(st.nextToken());
12+
long K = Integer.parseInt(st.nextToken());
13+
14+
BFSFindSUM(N, K);
15+
if (minV==Integer.MAX_VALUE){
16+
System.out.println(-1);
17+
}else {
18+
System.out.println(minV);
19+
}
20+
21+
22+
}
23+
24+
private static void BFSFindSUM(Long n, Long k) {
25+
Deque<long[]> dq = new LinkedList<>();
26+
dq.offer(new long[]{n, 1});
27+
while (!dq.isEmpty()) {
28+
long [] now = dq.pollFirst();
29+
long value = now[0];
30+
long count = now[1];
31+
if (value==k){
32+
minV= (int) Math.min(minV,count);
33+
}
34+
if (value <= k) {
35+
dq.offer(new long[]{value * 2, count + 1});
36+
dq.offer(new long[]{Long.valueOf(String.valueOf(value) +"1"), count + 1});
37+
}
38+
39+
40+
}
41+
42+
}
43+
}

0 commit comments

Comments
 (0)