File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ private static BufferedReader br;
7+ public static void main (String [] args ) throws IOException {
8+ br = new BufferedReader (new InputStreamReader (System . in));
9+ String [] temp = br. readLine(). split(" " );
10+ int N = Integer . parseInt(temp[0 ]);
11+ int M = Integer . parseInt(temp[1 ]);
12+
13+ Map<Integer , Integer > move = new HashMap<> ();
14+ for (int i = 0 ; i < N ; i++ ) {
15+ temp = br. readLine(). split(" " );
16+ move. put(Integer . parseInt(temp[0 ]), Integer . parseInt(temp[1 ]));
17+ }
18+ for (int i = 0 ; i < M ; i++ ) {
19+ temp = br. readLine(). split(" " );
20+ move. put(Integer . parseInt(temp[0 ]), Integer . parseInt(temp[1 ]));
21+ }
22+ boolean [] visited = new boolean [101 ];
23+ Queue<int[]> q = new ArrayDeque<> ();
24+ q. add(new int []{1 , 0 }); // QElement: {현재칸, 주사위횟수}
25+ visited[1 ] = true ;
26+ while (! q. isEmpty()) {
27+ //
28+ int [] cur = q. poll();
29+ int now = cur[0 ];
30+ int count = cur[1 ];
31+ if (now == 100 ) {
32+ System . out. println(count);
33+ return ;
34+ }
35+
36+ for (int d = 1 ; d <= 6 ; d++ ) {
37+ int np = now + d;
38+ if (np > 100 ) continue ;
39+ if (move. containsKey(np))
40+ np = move. get(np);
41+ if (! visited[np]) {
42+ visited[np] = true ;
43+ q. add(new int []{np, count + 1 });
44+ }
45+ }
46+ }
47+ }
48+ }
49+ ```
You can’t perform that action at this time.
0 commit comments