Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- dfs
- binary search
- DP
- 프로그래머스
- 자바
- 코테
- 투포인터
- SWEA
- 건강
- priorityqueue
- greedy
- oracle
- BFS
- COS PRO
- 이분탐색
- 문제풀이
- db
- 문제해결
- Java
- math
- 시뮬레이션
- BOJ
- 백준
- 운동기록
- 코딩테스트
- SQL
- MySQL
- 문자열
- 알고리즘
- 러닝일지
Archives
- Today
- Total
슈콩
[BOJ] 5014 스타트링크 본문

[문제]
https://www.acmicpc.net/problem/5014
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int f = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());
int g = Integer.parseInt(st.nextToken());
int u = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int[] distance = new int[f+1];
Arrays.fill(distance, -1);
Queue<Integer> q = new LinkedList<>();
q.offer(s);
distance[s] = 0;
while(!q.isEmpty()) {
int curr = q.poll();
if(curr==g) {
System.out.println(distance[g]);
return;
}
int up = curr + u;
if(up<=f && distance[up]==-1) {
distance[up] = distance[curr] + 1;
q.offer(up);
}
int down = curr - d;
if(down>=1 && distance[down]==-1) {
distance[down] = distance[curr] + 1;
q.offer(down);
}
}
System.out.println("use the stairs");
}
}
시작점 0으로 하는 경우, 지나갈 때 덮을 수 있음 -> -1로 고정 후, 이미 지나간 곳은 변경되지 않도록 방지 !
'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 2573 빙산 (0) | 2025.11.28 |
|---|---|
| [BOJ] 2468 안전 영역 (0) | 2025.11.28 |
| [BOJ] 7569 토마토 (0) | 2025.11.28 |
| [BOJ] 2644 촌수계산 (0) | 2025.11.28 |
| [BOJ] 2667 단지번호붙이기 (0) | 2025.11.27 |