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 |
Tags
- 언리얼엔진5
- 1563
- baekjoon
- Unreal Engine5
- NRVO
- 오블완
- DirectX11
- C++
- Programmers
- C
- Frustum
- directx
- 백준
- 2294
- TObjectPtr
- 팰린드롬 만들기
- UnrealEngine5
- UnrealEngine4
- RVO
- 티스토리챌린지
- softeer
- GeeksForGeeks
- const
- 줄 세우기
- RootMotion
- 프로그래머스
- UE5
- IFileDialog
- winapi
- algorithm
Archives
- Today
- Total
Game Develop
[Algorithm] Baekjoon 2636번 : 치즈 본문
https://www.acmicpc.net/problem/2636
2636번: 치즈
첫째 줄에는 사각형 모양 판의 세로와 가로의 길이가 양의 정수로 주어진다. 세로와 가로의 길이는 최대 100이다. 판의 각 가로줄의 모양이 윗 줄부터 차례로 둘째 줄부터 마지막 줄까지 주어진
www.acmicpc.net
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
struct Node
{
int y;
int x;
};
int row, col;
int arr[101][101] = { 0 };
int dir[4][2] = { {-1,0}, {1,0}, {0,-1}, {0,1} };
bool visited[101][101] = { false };
int prevMeltedCheese = 0;
int curMeltedCheese = 0;
void BFS()
{
memset(visited, false, sizeof(visited));
queue<Node> q;
q.push({ 0,0 });
visited[0][0] = true;
int cheeseCount = 0;
while (!q.empty())
{
int curY = q.front().y;
int curX = q.front().x;
q.pop();
for (int i = 0; i < 4; ++i)
{
int nextY = curY + dir[i][0];
int nextX = curX + dir[i][1];
if (nextY < 0 || nextY >= row) continue;
if (nextX < 0 || nextX >= col) continue;
if (visited[nextY][nextX] == true) continue;
visited[nextY][nextX] = true;
if (arr[nextY][nextX] == 1) // 치즈칸이면
{
arr[nextY][nextX] = 0;
++cheeseCount;
}
else // 빈공간이면
{
q.push({ nextY,nextX });
}
}
}
curMeltedCheese = cheeseCount;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> row >> col;
for (int i = 0; i < row; ++i)
{
for (int j = 0; j < col; ++j)
{
cin >> arr[i][j];
}
}
int hour = 0;
while (1)
{
BFS(); // 일단 돌려서 녹은 치즈개수 체크.
if (curMeltedCheese == 0) break;
++hour;
prevMeltedCheese = curMeltedCheese;
}
cout << hour << endl << prevMeltedCheese;
}
|
cs |
제일 외각의 치즈만 계속 녹이면 되는 문제다.
즉 0,0부터 BFS로 탐색하면서 처음 만나는 치즈를 녹이고 방문표시 후, 0으로 바꿔놓는 작업만 반복하면 된다.
치즈를 녹일때마다 카운팅해주고 녹인 치즈개수가 0이라면 반복문을 탈출하고 hour와 계속 기록해놨던 이전녹은치즈개수(prevMeltedCheese)를 출력해주면 된다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm] Baekjoon 11779번 : 최소비용 구하기 2 (0) | 2023.01.18 |
---|---|
[Algorithm] Baekjoon 2638번 : 치즈 (0) | 2023.01.18 |
[Algorithm] Baekjoon 2206번 : 벽 부수고 이동하기 (0) | 2023.01.07 |
[Algorithm] Baekjoon 11657번 : 타임머신 (1) | 2023.01.03 |
[Algorithm]Baekjoon 1238번 :: 파티 (0) | 2022.12.22 |