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
- BOJ
- SQL
- db
- 투포인터
- 이분탐색
- COS PRO
- 코테
- 문제풀이
- 시뮬레이션
- 운동기록
- greedy
- dfs
- 백준
- 문자열
- 건강
- 러닝일지
- priorityqueue
- 문제해결
- 프로그래머스
- BFS
- SWEA
- binary search
- 알고리즘
- DP
- 자바
- 코딩테스트
- MySQL
- math
- oracle
- Java
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 IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int t = Integer.parseInt(br.readLine());
while(t-->0) {
int n = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine());
int houseR = Integer.parseInt(st.nextToken());
int houseC = Integer.parseInt(st.nextToken());
int[][] point = new int[n][2];
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
point[i][0] = Integer.parseInt(st.nextToken());
point[i][1] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(br.readLine());
int endR = Integer.parseInt(st.nextToken());
int endC = Integer.parseInt(st.nextToken());
boolean can = false;
boolean[] visit = new boolean[n];
Queue<int[]> q = new LinkedList<>();
q.offer(new int[] {houseR,houseC});
while(!q.isEmpty()) {
int[] curr = q.poll();
int check = Math.abs(curr[0]-endR) + Math.abs(curr[1]-endC);
if(check<=1000) {
can = true;
}
for(int i=0;i<n;i++) {
if(!visit[i]) {
int diff = Math.abs(curr[0] - point[i][0]) + Math.abs(curr[1] - point[i][1]);
if(diff<=1000) {
visit[i] = true;
q.offer(new int[] {point[i][0],point[i][1]});
}
}
}
}
if(can) {
System.out.println("happy");
}else {
System.out.println("sad");
}
}
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 14503 로봇 청소기 (0) | 2026.02.22 |
|---|---|
| [BOJ] 2573 빙산 (0) | 2026.02.09 |
| [BOJ] 2468 안전 영역 (0) | 2026.02.09 |
| [BOJ] 5014 스타트링크 (0) | 2026.02.02 |
| [BOJ] 1697 숨바꼭질 (0) | 2026.01.28 |