Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17-kokeunho #64

Open
wants to merge 1 commit into
base: 16-kokeunho
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified kokeunho/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
| 14μ°¨μ‹œ | 2025.01.08 | κ·Έλž˜ν”„ 탐색 | [λ―Έλ‘œλ§Œλ“€κΈ°](https://www.acmicpc.net/problem/2665) | [#55](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/55) |
| 15μ°¨μ‹œ | 2025.01.12 | μ‘°ν•©λ‘  | [κ²©μžμƒμ˜ 경둜](https://www.acmicpc.net/problem/10164) | [#58](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/58) |
| 16μ°¨μ‹œ | 2025.01.19 | κ·Έλž˜ν”„ 탐색 | [DFS와 BFS](https://www.acmicpc.net/problem/1260) | [#63](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/63) |
| 17μ°¨μ‹œ | 2025.01.20 | κ·Έλž˜ν”„ 탐색 | [μ•ˆμ „ μ˜μ—­](https://www.acmicpc.net/problem/2468) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/64) |
---
51 changes: 51 additions & 0 deletions kokeunho/κ·Έλž˜ν”„ 탐색/17-kokeunho.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java.util.*;

public class Main {
static int n;
static int[][] map;
static boolean[][] visited;
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

n = sc.nextInt();
map = new int[n][n];
visited = new boolean[n][n];

int max_height = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
map[i][j] = sc.nextInt();
max_height = Math.max(max_height, map[i][j]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ΄λ ‡κ²Œ ν•΄μ„œ h의 탐색 λ²”μœ„λ₯Ό μ€„μ΄μ…¨κ΅°μš”! 쒋은 μ•„μ΄λ””μ–΄λ„€μš”

}
}

int max_area = 0;
for (int h = 0; h <= max_height; h++) {
visited = new boolean[n][n];
int safe_area = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (!visited[i][j] && map[i][j] > h) {
dfs(i, j, h);
safe_area++;
}
}
}
max_area = Math.max(max_area, safe_area);
}
System.out.print(max_area);
}
public static void dfs(int startX, int startY, int height) {
visited[startX][startY] = true;
for (int i = 0; i < 4; i++) {
int nx = startX + dx[i];
int ny = startY + dy[i];
if (nx >= 0 && nx < n && ny >= 0 && ny < n && !visited[nx][ny] && map[nx][ny] > height) {
dfs(nx, ny, height);
}
}
}
}
Loading