728x90
https://www.acmicpc.net/problem/5014
package BKD_0x9_BFS;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class BOJ_5014 {
static int[] floor;
static int[] d;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int F = sc.nextInt();
int S = sc.nextInt();
int G = sc.nextInt();
int U = sc.nextInt();
int D = sc.nextInt() * -1;
floor = new int[F + 1];
d = new int[]{U, D};
System.out.println(bfs(S,G,F));
}
static String bfs(int start, int dst, int height){
Queue<Integer> q = new LinkedList<>();
q.offer(start);
floor[start]=1;
while (!q.isEmpty()){
int f = q.poll();
if(f==dst) {
return Integer.toString(floor[f]-1);
}
for(int i=0;i<2;i++){
int nd = f+d[i];
if(nd>0 && nd<=height && floor[nd]==0){
floor[nd] = floor[f]+1;
q.offer(nd);
}
}
}
return "use the stairs";
}
}
쉽고 빠르게 호로로록 와랄랄라라 피룰로로로롤 꺄르라라라라랄랄 냐하하하하핳하하하 풀었따.
728x90
'🐣 알고리즘 삐약 > 💻 백준 삐약' 카테고리의 다른 글
67 삐약 : 백준 5427| 불 [바킹독 문제 풀이|BFS|JAVA] (0) | 2024.06.07 |
---|---|
66 삐약 : 백준 13549| 숨바꼭질3 [바킹독 문제 풀이|BFS|JAVA] (0) | 2024.06.04 |
64 삐약 : 백준 6593| 상범 빌딩 [바킹독 문제 풀이|BFS|JAVA] (0) | 2024.06.04 |
63 삐약 : 백준 10026| 적록색약 [바킹독 문제 풀이|BFS|JAVA] (0) | 2024.06.03 |
62 삐약 : 백준 7569| 토마토 [바킹독 문제 풀이|BFS|JAVA] (0) | 2024.06.03 |