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
- MySQL
- 건강
- 문자열
- 문제해결
- 코테
- 문제풀이
- math
- SQL
- greedy
- 투포인터
- binary search
- DP
- 백준
- BFS
- BOJ
- 프로그래머스
- 알고리즘
- 이분탐색
- priorityqueue
- dfs
- 자바
- oracle
- db
- 코딩테스트
- 시뮬레이션
- Java
- SWEA
- 운동기록
- 러닝일지
- COS PRO
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 IOException {
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[] floor = new int[f+1];
Queue<int[]> q = new LinkedList<>();
boolean[] next = new boolean[f+1];
next[s] = true;
q.offer(new int[] {s,0});
while(!q.isEmpty()) {
int[] curr = q.poll();
if(curr[0]==g) {
System.out.println(curr[1]);
System.exit(0);;
}
if(curr[0]+u<=f && !next[curr[0]+u]) {
next[curr[0]+u] = true;
q.offer(new int[]{curr[0]+u,curr[1]+1});
}
if(curr[0]-d>0 && !next[curr[0]-d]) {
next[curr[0]-d] = true;
q.offer(new int[] {curr[0]-d,curr[1]+1});
}
}
System.out.println("use the stairs");
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 2573 빙산 (0) | 2025.09.30 |
|---|---|
| [BOJ] 백준 2468 안전 영역 (0) | 2025.09.30 |
| [BOJ] 백준 1697 숨바꼭질 (0) | 2025.09.30 |
| [BOJ] 백준 7569 토마토 (0) | 2025.09.29 |
| [BOJ] 백준 2644 촌수계산 (0) | 2025.09.29 |