Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
JWeonseok merged 46 commits into main from JWonseok_wed_algo
Oct 11, 2021
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 Sep 29, 2021
7c07b7d
210929 : BOJ 14470 정원석
JWeonseok Sep 29, 2021
69ae321
210929 : BOJ 1911 정원석
JWeonseok Sep 29, 2021
fb89ba2
210929 : BOJ 2212 정원석
JWeonseok Sep 29, 2021
25720ce
210929 : BOJ 2212 정원석
JWeonseok Sep 29, 2021
582b128
210929 : BOJ 2258 정원석
JWeonseok Sep 29, 2021
9d1a30d
210929 : BOJ 2262 정원석
JWeonseok Sep 29, 2021
cd77a47
210929 : BOJ 11000 정원석
JWeonseok Sep 29, 2021
d80960d
210929 : BOJ 11399 정원석
JWeonseok Sep 29, 2021
b38bad6
210929 : BOJ 1339 정원석
JWeonseok Sep 29, 2021
dcf891b
210929 : BOJ 1715 정원석
JWeonseok Sep 29, 2021
54aa4f0
210929 : BOJ 1744 정원석
JWeonseok Sep 29, 2021
16e0c7a
210929 : BOJ 1012 정원석
JWeonseok Sep 29, 2021
b4f27da
210929 : BOJ 1167 정원석
JWeonseok Sep 29, 2021
9e85945
210929 : BOJ 11724 정원석
JWeonseok Sep 29, 2021
c678e8f
210929 : BOJ 1260 정원석
JWeonseok Sep 29, 2021
efb4a34
210929 : BOJ 13549 정원석
JWeonseok Sep 29, 2021
5a9628a
210929 : BOJ 14442 정원석
JWeonseok Sep 29, 2021
3f81324
210929 : BOJ 1600 정원석
JWeonseok Sep 29, 2021
4239f26
210929 : BOJ 16929 정원석
JWeonseok Sep 29, 2021
4c6d0ff
210929 : BOJ 16956 정원석
JWeonseok Sep 29, 2021
cf64e1d
210929 : BOJ 1707 정원석
JWeonseok Sep 29, 2021
88b0013
210929 : BOJ 1726 정원석
JWeonseok Sep 29, 2021
4e25d4b
210929 : BOJ 1743 정원석
JWeonseok Sep 29, 2021
7c28028
210929 : BOJ 17471 정원석
JWeonseok Sep 29, 2021
07517ce
210929 : BOJ 1967 정원석
JWeonseok Sep 29, 2021
18fcf51
210929 : BOJ 2146 정원석
JWeonseok Sep 29, 2021
98ad824
210929 : BOJ 2206 정원석
JWeonseok Sep 29, 2021
d06826c
210929 : BOJ 2210 정원석
JWeonseok Sep 29, 2021
8d33c75
210929 : BOJ 2234 정원석
JWeonseok Sep 29, 2021
df61552
210929 : BOJ 2468 정원석
JWeonseok Sep 29, 2021
c2625d9
210929 : BOJ 2583 정원석
JWeonseok Sep 29, 2021
d9558ce
210929 : BOJ 2606 정원석
JWeonseok Sep 29, 2021
5c6dcbc
210929 : BOJ 2636 정원석
JWeonseok Sep 29, 2021
6e3f99b
210929 : BOJ 2638 정원석
JWeonseok Sep 29, 2021
21f3114
210929 : BOJ 2644 정원석
JWeonseok Sep 29, 2021
cf8e11a
210929 : BOJ 2665 정원석
JWeonseok Sep 29, 2021
0dda38b
210929 : BOJ 2667 정원석
JWeonseok Sep 29, 2021
24ae20b
210929 : BOJ 3055 정원석
JWeonseok Sep 29, 2021
fd71593
210929 : BOJ 4179 정원석
JWeonseok Sep 29, 2021
d0e595c
210929 : BOJ 5014 정원석
JWeonseok Sep 29, 2021
edfe7b3
210929 : BOJ 6593 정원석
JWeonseok Sep 29, 2021
ba914fe
210929 : BOJ 7569 정원석
JWeonseok Sep 29, 2021
0a8d8c8
210929 : BOJ 7576 정원석
JWeonseok Sep 29, 2021
1578d6d
210929 : BOJ 9019 정원석
JWeonseok Sep 29, 2021
ea93cb1
210929 : BOJ 9205 정원석
JWeonseok Sep 29, 2021
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
Prev Previous commit
Next Next commit
210929 : BOJ 2638 정원석
  • Loading branch information
JWeonseok committed Sep 29, 2021
commit 6e3f99b587f47a3cf3f1a40a3a6a720e3b80c119
120 changes: 120 additions & 0 deletions Baekjoon/2638/Main_정원석.java
View file Open in desktop
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;
}
}

}

AltStyle によって変換されたページ (->オリジナル) /