File tree 3 files changed +74
-0
lines changed
3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 42
42
| 07 | | [ Baekjoon-1525 ํผ์ฆ] ( ./src/BFS/P1525 ) | |
43
43
| 08 | | [ Baekjoon-7576 ํ ๋งํ ] ( ./src/BFS/P7576 ) | |
44
44
| 09 | | [ Baekjoon-1697 ์จ๋ฐ๊ผญ์ง] ( ./src/BFS/P1697 ) | |
45
+ | 10 | | [ Baekjoon-14226 ์ด๋ชจํฐ์ฝ] ( ./src/BFS/P14226 ) | |
45
46
46
47
## Simulation
47
48
Original file line number Diff line number Diff line change
1
+ package BFS .P14226 ;
2
+
3
+ import java .util .*;
4
+
5
+ public class Main {
6
+
7
+ static int S ;
8
+ static Queue <State > q = new LinkedList <>();
9
+ static boolean [][] visited = new boolean [10001 ][10001 ];
10
+
11
+ public static void main (String [] args ) {
12
+ Scanner sc = new Scanner (System .in );
13
+ S = sc .nextInt ();
14
+
15
+ int ans = 0 ;
16
+ q .offer (new State (1 , 0 , 0 ));
17
+ while (!q .isEmpty ()) {
18
+ State s = q .poll ();
19
+ visited [s .screen ][s .clip ] = true ;
20
+
21
+ if (s .screen == S ) {
22
+ ans = s .time ;
23
+ break ;
24
+ } else if (!visited [s .screen ][s .screen ]) {
25
+ q .add (new State (s .screen , s .screen , s .time + 1 ));
26
+ }
27
+
28
+ if (s .screen + s .clip == S ) {
29
+ ans = s .time + 1 ;
30
+ break ;
31
+ } else if (s .clip != 0 && !visited [s .screen + s .clip ][s .clip ]) {
32
+ q .add (new State (s .screen + s .clip , s .clip , s .time + 1 ));
33
+ }
34
+
35
+ if (s .screen - 1 == S ) {
36
+ ans = s .time + 1 ;
37
+ break ;
38
+ } else if (s .screen >= 1 && !visited [s .screen - 1 ][s .clip ]) {
39
+ q .add (new State (s .screen - 1 , s .clip , s .time + 1 ));
40
+ }
41
+ }
42
+
43
+ System .out .println (ans );
44
+ }
45
+ }
46
+
47
+ class State {
48
+ int screen ;
49
+ int clip ;
50
+ int time ;
51
+
52
+ public State (int screen , int clip , int time ) {
53
+ this .screen = screen ;
54
+ this .clip = clip ;
55
+ this .time = time ;
56
+ }
57
+
58
+ @ Override
59
+ public String toString () {
60
+ return "State{" +
61
+ "screen=" + screen +
62
+ ", clip=" + clip +
63
+ ", time=" + time +
64
+ '}' ;
65
+ }
66
+ }
Original file line number Diff line number Diff line change
1
+ ## [ baekjoon-14226] ์ด๋ชจํฐ์ฝ
2
+
3
+ ![ image] ( https://user-images.githubusercontent.com/22045163/101236473-dce80980-3714-11eb-9b64-dde07af86818.png )
4
+
5
+ 1 . BFS๋ก ํ ์ ์๋ ๋ฌธ์ ์์ ๊นจ๋ซ๊ธฐ
6
+ 2 . ๋ฌธ์ ์กฐ๊ฑด์ ์ ํ์
ํ๊ณ ์ ํํ ์กฐ๊ฑด ๊ตฌํํ๊ธฐ
7
+ 3 . BFS์์ ์ฃผ์ํด์ผ ํ๋ ๋ฉ๋ชจ๋ฆฌ ์ด๊ณผ ๋ฌธ์ ๊ธฐ์ตํ๊ธฐ !!
You canโt perform that action at this time.
0 commit comments