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
- SQL
- 문제해결
- oracle
- 러닝일지
- 문자열
- math
- 백준
- 자바
- db
- greedy
- 프로그래머스
- 알고리즘
- 투포인터
- 건강
- 코테
- Java
- dfs
- COS PRO
- BOJ
- 운동기록
- 이분탐색
- priorityqueue
- DP
- BFS
- SWEA
- binary search
- 문제풀이
- 코딩테스트
- 시뮬레이션
Archives
- Today
- Total
슈콩
[BOJ] 5014 스타트링크 본문
[문제]
https://www.acmicpc.net/problem/5014
[소스 코드]
import java.util.*;
import java.io.*;
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[] floors = new int[f+1];
boolean[] visit = new boolean[f+1];
Queue<int[]> q = new LinkedList<>();
q.offer(new int[] {0,s});
visit[s] = true;
while(!q.isEmpty()) {
int[] curr = q.poll();
if(curr[1]==g) {
System.out.println(curr[0]);
return;
}
if(curr[1]+u<=f && !visit[curr[1]+u]) {
visit[curr[1]+u] = true;
q.offer(new int[] {curr[0]+1,curr[1]+u});
}
if(curr[1]-d>=1 && !visit[curr[1]-d]) {
visit[curr[1]-d] = true;
q.offer(new int[] {curr[0]+1,curr[1]-d});
}
}
System.out.println("use the stairs");
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 2573 빙산 (0) | 2026.02.09 |
|---|---|
| [BOJ] 2468 안전 영역 (0) | 2026.02.09 |
| [BOJ] 1697 숨바꼭질 (0) | 2026.01.28 |
| [BOJ] 7569 토마토 (0) | 2026.01.26 |
| [BOJ] 2664 촌수계산 (0) | 2026.01.22 |