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
- SWEA
- 프로그래머스
- COS PRO
- 운동기록
- binary search
- 시뮬레이션
- 투포인터
- SQL
- 코테
- Java
- 러닝일지
- 코딩테스트
- db
- MySQL
- 문제풀이
- 백준
- 이분탐색
- math
- 자바
- greedy
- BFS
- BOJ
- oracle
- priorityqueue
- 문제해결
- 건강
- 알고리즘
- dfs
- 문자열
Archives
- Today
- Total
슈콩
[BOJ] 백준 17143 낚시왕 본문
[문제]
https://www.acmicpc.net/problem/17143
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static class Shark{
int r,c,s,d,z;
Shark(int r,int c,int s,int d,int z){
this.r = r;
this.c = c;
this.s = s;
this.d = d;
this.z = z;
}
}
static Shark[][] map;
static int[] dr = {-1,0,1,0};
static int[] dc = {0,-1,0,1};
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int R = Integer.parseInt(st.nextToken());
int C = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
map = new Shark[R][C];
for(int i=0;i<M;i++) {
st = new StringTokenizer(br.readLine());
int r = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int z = Integer.parseInt(st.nextToken());
if(d==1) d=0;
if(d==4) d=1;
if(d==0 || d==2) s %= (R-1)*2;
if(d==1 || d==3) s %= (C-1)*2;
map[r-1][c-1] = new Shark(r-1,c-1,s,d,z);
}
int result = 0;
for(int col=0;col<C;col++) {
for(int row=0;row<R;row++) {
if(map[row][col]!=null) {
result += map[row][col].z;
map[row][col] = null;
break;
}
}
Queue<Shark> q = new LinkedList<>();
for(int i=0;i<R;i++) {
for(int j=0;j<C;j++) {
if(map[i][j]!=null) {
q.offer(map[i][j]);
}
}
}
map = new Shark[R][C];
while(!q.isEmpty()) {
Shark curr = q.poll();
int speed = curr.s;
for(int i=0;i<speed;i++) {
int nr = curr.r + dr[curr.d];
int nc = curr.c + dc[curr.d];
if(nr<0 || nr>=R || nc<0 || nc>=C) {
curr.r -= dr[curr.d];
curr.c -= dc[curr.d];
curr.d = (curr.d+2)%4;
continue;
}
curr.r = nr;
curr.c = nc;
}
if(map[curr.r][curr.c]!=null) {
if(map[curr.r][curr.c].z<curr.z) {
map[curr.r][curr.c] = curr;
}
}
else {
map[curr.r][curr.c] = curr;
}
}
}
System.out.println(result);
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 17281 ⚾ (0) | 2025.09.26 |
|---|---|
| [BOJ] 백준 17144 미세먼지 안녕! (2) | 2025.09.26 |
| [BOJ] 백준 17142 연구소 3 (0) | 2025.09.25 |
| [BOJ] 백준 17141 연구소 2 (0) | 2025.09.25 |
| [BOJ] 백준 17135 캐슬 디펜스 (0) | 2025.09.25 |