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
- 문자열
- 시뮬레이션
- DP
- binary search
- 이분탐색
- math
- SQL
- Java
- BOJ
- oracle
- greedy
- 백준
- 투포인터
- 문제풀이
- 프로그래머스
- 러닝일지
- 알고리즘
- SWEA
- 건강
- COS PRO
- 자바
- MySQL
- priorityqueue
- 운동기록
- BFS
- 문제해결
- db
- 코테
- dfs
- 코딩테스트
Archives
- Today
- Total
슈콩
[BOJ] 9205 맥주 마시면서 걸어가기 본문


[문제]
https://www.acmicpc.net/problem/9205
[소스 코드]
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;
int t = Integer.parseInt(br.readLine());
for(int tc=1;tc<=t;tc++) {
int n = Integer.parseInt(br.readLine());
int[][] stores = new int[n+2][2];
for(int i=0;i<n+2;i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
stores[i][0] = x;
stores[i][1] = y;
}
boolean[] visit = new boolean[n+2];
Queue<Integer> q = new LinkedList<>();
q.offer(0);
boolean result = false;
while(!q.isEmpty()) {
int curr = q.poll();
if(curr==n+1) {
result = true;
break;
}
for(int i=1;i<n+2;i++) {
if(!visit[i]) {
int dist = Math.abs(stores[curr][0] - stores[i][0]) + Math.abs(stores[curr][1] - stores[i][1]);
if(dist<=1000) {
visit[i] = true;
q.offer(i);
}
}
}
}
if(result) System.out.println("happy");
else System.out.println("sad");
}
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 13460 구슬 탈출 2 (0) | 2025.11.30 |
|---|---|
| [BOJ] 14503 로봇 청소기 (0) | 2025.11.29 |
| [BOJ] 2573 빙산 (0) | 2025.11.28 |
| [BOJ] 2468 안전 영역 (0) | 2025.11.28 |
| [BOJ] 5014 스타트링크 (0) | 2025.11.28 |