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