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
- 코테
- 문제해결
- SWEA
- MySQL
- SQL
- dfs
- binary search
- Java
- COS PRO
- greedy
- 문제풀이
- 이분탐색
- db
- 알고리즘
- 러닝일지
- 운동기록
- oracle
- math
- 문자열
- 프로그래머스
- DP
- 자바
- 투포인터
- 시뮬레이션
- priorityqueue
- 백준
- BFS
- 코딩테스트
- 건강
- BOJ
Archives
- Today
- Total
슈콩
[BOJ] 백준 9205 맥주 마시면서 걸어가기 본문
[문제]
https://www.acmicpc.net/problem/9205
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n;
static int[][] stores;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int t = Integer.parseInt(br.readLine());
while(t-->0) {
n = Integer.parseInt(br.readLine());
stores = new int[n+2][2];
for(int i=0;i<=n+1;i++) {
st = new StringTokenizer(br.readLine());
stores[i][0] = Integer.parseInt(st.nextToken());
stores[i][1] = Integer.parseInt(st.nextToken());
}
if(possible()) {
System.out.println("happy");
}
else System.out.println("sad");
}
}
private static boolean possible() {
boolean[] next = new boolean[n+2];
Queue<Integer> q = new LinkedList<>();
q.offer(0);
next[0] = true;
while(!q.isEmpty()) {
int curr = q.poll();
if(curr==n+1) return true;
for(int i=1;i<=n+1;i++) {
if(!next[i]) {
int dis = Math.abs(stores[curr][0] - stores[i][0]) + Math.abs(stores[curr][1] - stores[i][1]);
if(dis<=1000) {
next[i] = true;
q.offer(i);
}
}
}
}
return false;
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 13458 시험 감독 (0) | 2025.10.02 |
|---|---|
| [BOJ] 백준 3190 뱀 (0) | 2025.10.02 |
| [BOJ] 백준 2573 빙산 (0) | 2025.09.30 |
| [BOJ] 백준 2468 안전 영역 (0) | 2025.09.30 |
| [BOJ] 백준 5014 스타트링크 (0) | 2025.09.30 |