Skip to content

Commit 3e81d56

Browse files
committed
1002
1 parent a0f1055 commit 3e81d56

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-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/gold/BOJ12851/BOJ12851.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/gold/BOJ12851/src/Main.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.util.Deque;
2+
import java.util.LinkedList;
3+
import java.util.Scanner;
4+
5+
public class Main {
6+
static int TimeMin = (int) 1e9;
7+
static int count=0;
8+
static int [] visited;
9+
public static void main(String[] args) {
10+
11+
Scanner sc = new Scanner(System.in);
12+
int N = sc.nextInt();
13+
int K = sc.nextInt();
14+
visited= new int [100001];
15+
BFS(N, K);
16+
System.out.println(TimeMin);
17+
System.out.println(count);
18+
}
19+
20+
private static void BFS(int n, int k) {
21+
Deque<int[]> dq = new LinkedList<>();
22+
dq.offer(new int[]{n, 0});
23+
int flag=0;
24+
while (!dq.isEmpty()) {
25+
int[] now = dq.pollFirst();
26+
int place = now[0];
27+
int time = now[1];
28+
visited[place]=1;
29+
30+
if (place == k) {
31+
if(flag==0){
32+
TimeMin = time;
33+
count++;
34+
flag=1;
35+
}else if(flag==1 && TimeMin==time){
36+
count++;
37+
}
38+
39+
40+
}
41+
if (0 <= place - 1 && visited[place-1]==0) {
42+
dq.offer(new int[]{place - 1, time + 1});
43+
}
44+
if (place+1 < 100001 && visited[place+1]==0) {
45+
dq.offer(new int[]{place + 1, time + 1});
46+
}
47+
if(place*2 < 100001 && visited[place*2]==0){
48+
dq.offer(new int[]{place * 2, time + 1});
49+
}
50+
51+
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)