-
Notifications
You must be signed in to change notification settings - Fork 7
BOJ DFS/BFS & 그리디 집중 주간 문제 리스트 업데이트 #116
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
205327b
210929 : BOJ 1041 정원석
JWeonseok 7c07b7d
210929 : BOJ 14470 정원석
JWeonseok 69ae321
210929 : BOJ 1911 정원석
JWeonseok fb89ba2
210929 : BOJ 2212 정원석
JWeonseok 25720ce
210929 : BOJ 2212 정원석
JWeonseok 582b128
210929 : BOJ 2258 정원석
JWeonseok 9d1a30d
210929 : BOJ 2262 정원석
JWeonseok cd77a47
210929 : BOJ 11000 정원석
JWeonseok d80960d
210929 : BOJ 11399 정원석
JWeonseok b38bad6
210929 : BOJ 1339 정원석
JWeonseok dcf891b
210929 : BOJ 1715 정원석
JWeonseok 54aa4f0
210929 : BOJ 1744 정원석
JWeonseok 16e0c7a
210929 : BOJ 1012 정원석
JWeonseok b4f27da
210929 : BOJ 1167 정원석
JWeonseok 9e85945
210929 : BOJ 11724 정원석
JWeonseok c678e8f
210929 : BOJ 1260 정원석
JWeonseok efb4a34
210929 : BOJ 13549 정원석
JWeonseok 5a9628a
210929 : BOJ 14442 정원석
JWeonseok 3f81324
210929 : BOJ 1600 정원석
JWeonseok 4239f26
210929 : BOJ 16929 정원석
JWeonseok 4c6d0ff
210929 : BOJ 16956 정원석
JWeonseok cf64e1d
210929 : BOJ 1707 정원석
JWeonseok 88b0013
210929 : BOJ 1726 정원석
JWeonseok 4e25d4b
210929 : BOJ 1743 정원석
JWeonseok 7c28028
210929 : BOJ 17471 정원석
JWeonseok 07517ce
210929 : BOJ 1967 정원석
JWeonseok 18fcf51
210929 : BOJ 2146 정원석
JWeonseok 98ad824
210929 : BOJ 2206 정원석
JWeonseok d06826c
210929 : BOJ 2210 정원석
JWeonseok 8d33c75
210929 : BOJ 2234 정원석
JWeonseok df61552
210929 : BOJ 2468 정원석
JWeonseok c2625d9
210929 : BOJ 2583 정원석
JWeonseok d9558ce
210929 : BOJ 2606 정원석
JWeonseok 5c6dcbc
210929 : BOJ 2636 정원석
JWeonseok 6e3f99b
210929 : BOJ 2638 정원석
JWeonseok 21f3114
210929 : BOJ 2644 정원석
JWeonseok cf8e11a
210929 : BOJ 2665 정원석
JWeonseok 0dda38b
210929 : BOJ 2667 정원석
JWeonseok 24ae20b
210929 : BOJ 3055 정원석
JWeonseok fd71593
210929 : BOJ 4179 정원석
JWeonseok d0e595c
210929 : BOJ 5014 정원석
JWeonseok edfe7b3
210929 : BOJ 6593 정원석
JWeonseok ba914fe
210929 : BOJ 7569 정원석
JWeonseok 0a8d8c8
210929 : BOJ 7576 정원석
JWeonseok 1578d6d
210929 : BOJ 9019 정원석
JWeonseok ea93cb1
210929 : BOJ 9205 정원석
JWeonseok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210929 : BOJ 2638 정원석
- Loading branch information
commit 6e3f99b587f47a3cf3f1a40a3a6a720e3b80c119
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
Baekjoon/2638/Main_정원석.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package dfsbfs; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.InputStreamReader; | ||
| import java.util.ArrayList; | ||
| import java.util.LinkedList; | ||
| import java.util.Queue; | ||
| import java.util.StringTokenizer; | ||
|
|
||
| /* | ||
| * 210709 fri 치즈 | ||
| * | ||
| * 이 문제의 키포인트는 공기의 내외부를 판단할 수 있는지이다. | ||
| * 처음 접근했을 때는 이 부분을 간과해서 틀렸고 | ||
| * 두 번째로는 내부 공기를 판단하여 녹는 치즈칸을 판단했는데 | ||
| * 내부 공기를 판단하는 로직이 틀렸었다. 실제로 정확히 내부 공기를 판별하는 것은 | ||
| * 거의 불가능할 정도로 까다로웠다. 해답은 외부 공기를 판별하는 것이다. | ||
| * bfs를 이용하면 외부 공기를 간단하게 판별이 가능했다. | ||
| * */ | ||
|
|
||
| public class No2638_치즈 { | ||
|
|
||
| static int N, M, cheezeSize = 0, ans = 0; | ||
| static int[][] map; | ||
| static boolean[][] chk; | ||
| static ArrayList<point> hole; | ||
| static Queue<point> cheeze, melt; | ||
|
|
||
| static int[] dx = {-1, 0, 1, 0}; | ||
| static int[] dy = {0, 1, 0, -1}; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
|
|
||
| BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
|
||
| N = Integer.parseInt(st.nextToken()); | ||
| M = Integer.parseInt(st.nextToken()); | ||
|
|
||
| map = new int[N][M]; | ||
| cheeze = new LinkedList<>(); | ||
| melt = new LinkedList<>(); | ||
|
|
||
| for (int i = 0; i < N; i++) { | ||
| st = new StringTokenizer(br.readLine()); | ||
| for (int j = 0; j < M; j++) { | ||
| map[i][j] = Integer.parseInt(st.nextToken()); | ||
| if(map[i][j] == 1) { | ||
| cheeze.offer(new point(i, j)); | ||
| cheezeSize++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| while(cheezeSize > 0) { | ||
|
|
||
| makeExternal(); | ||
|
|
||
| int size = cheeze.size(); | ||
| for (int i = 0; i < size; i++) { | ||
| point cur = cheeze.poll(); | ||
| int cnt = 0; | ||
| for (int j = 0; j < 4; j++) { | ||
| int nx = cur.x + dx[j]; | ||
| int ny = cur.y + dy[j]; | ||
|
|
||
| if(chkvalid(nx, ny) && map[nx][ny] == 2) cnt++; | ||
| } | ||
| if(cnt >= 2) melt.offer(cur); | ||
| else cheeze.offer(cur); | ||
| } | ||
|
|
||
| cheezeSize -= melt.size(); | ||
|
|
||
| while(!melt.isEmpty()) { | ||
| point tmp = melt.poll(); | ||
| map[tmp.x][tmp.y] = 0; | ||
| } | ||
| ans++; | ||
| } | ||
|
|
||
| System.out.println(ans); | ||
|
|
||
| } | ||
| static void makeExternal() { | ||
| Queue<point> q = new LinkedList<>(); | ||
| chk = new boolean[N][M]; | ||
| q.offer(new point(0, 0)); | ||
| chk[0][0] = true; | ||
|
|
||
| while(!q.isEmpty()) { | ||
| point cur = q.poll(); | ||
| for (int k = 0; k < 4; k++) { | ||
| int nx = cur.x + dx[k]; | ||
| int ny = cur.y + dy[k]; | ||
| if(chkvalid(nx, ny) && map[nx][ny] != 1 && !chk[nx][ny]) { | ||
| q.offer(new point(nx, ny)); | ||
| map[nx][ny] = 2; | ||
| chk[nx][ny] = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static boolean chkvalid(int x, int y) { | ||
| if(x < 0 || x >= N || y < 0 || y >= M) return false; | ||
| return true; | ||
| } | ||
|
|
||
| static class point{ | ||
| int x, y; | ||
|
|
||
| public point(int x, int y) { | ||
| super(); | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.