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
- 이펙티브코틀린
- FIFO paging
- 윤성우 저자
- 스프링 입문
- 10026번
- 김영한
- 운영체제
- Window-Via-c/c++
- 스프링 핵심 원리
- 열혈 tcp/ip 프로그래밍
- 2475번
- redis
- 에러핸들링
- Operating System
- BOJ
- C#
- Spring
- C++
- 토마토
- HTTP
- 제프리리처
- TCP/IP
- 우아한레디스
- inflearn
- OS
- 열혈 TCP/IP 소켓 프로그래밍
- Operating System.
- Four Squares
- 우아한 테크 세미나
- n타일링2
Archives
- Today
- Total
나의 브을로오그으
[c++] 7569번 : 토마토 본문
https://www.acmicpc.net/problem/7569
#include <iostream>
#include <queue>
using namespace std;
#define RIPE 1
#define NOT_RIPE 0
#define NEVER_RIPE -1
int tomatoBox[101][101][101] = { 0, };
int M, N, H;
struct Point3 {
int m;
int n;
int h;
};
bool IsNotRipeTomato() {
for (int h = 1; h <= H; ++h)
{
for (int n = 1; n <= N; ++n)
{
for (int m = 1; m <= M; ++m)
{
if (tomatoBox[h][n][m] == NOT_RIPE)
{
return true;
}
}
}
}
return false;
}
bool IsBoundOfBox(int m, int n, int h)
{
return h >= 1 && n >= 1 && m >= 1 && h <= H && n <= N && m <= M;
}
void ChangeTomato(queue<Point3>& tomatoQ, const Point3& _pt)
{
int h, n, m;
for (int i = 0; i < 3; ++i)
{
for (int j = -1; j < 2; j+=2)
{
h = i == 2 ? _pt.h + j : _pt.h;
n = i == 1 ? _pt.n + j : _pt.n;
m = i == 0 ? _pt.m + j : _pt.m;
if (IsBoundOfBox(m, n, h) == true && tomatoBox[h][n][m] == NOT_RIPE)
{
tomatoBox[h][n][m] = RIPE;
tomatoQ.push(Point3{ m, n, h });
}
}
}
return;
}
int CountOfDaysForRipeTomato(queue<Point3>& tomatoQ) {
int days = 0;
while (true)
{
int len = tomatoQ.size();
for (int i = 0; i < len; ++i)
{
Point3 tomatoInfo = tomatoQ.front();
ChangeTomato(tomatoQ, tomatoInfo);
tomatoQ.pop();
}
if (tomatoQ.empty() == true)
{
break;
}
else
{
++days;
}
}
return IsNotRipeTomato() == true ? -1 : days;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
queue<Point3> tomatoQ;
int days;
cin >> M >> N >> H;
for (int h = 1; h <= H; ++h)
{
for (int n = 1; n <= N; ++n)
{
for (int m = 1; m <= M; ++m)
{
cin >> tomatoBox[h][n][m];
if (tomatoBox[h][n][m] == RIPE)
{
tomatoQ.push(Point3{ m, n, h });
}
}
}
}
days = CountOfDaysForRipeTomato(tomatoQ);
cout << days << '\n';
return 0;
}
'알고리즘 > BaekJoon' 카테고리의 다른 글
[c++] 7662번 : 이중 우선순위 큐 (0) | 2022.10.26 |
---|---|
[c++] 7576번 : 토마토 (0) | 2022.10.21 |
[c++] 18870번 : 좌표 압축 (0) | 2022.10.12 |
[c++] 17626번 : Four Squares (0) | 2022.10.04 |
[c++] 11727번 : 2 x n 타일링 2 (0) | 2022.09.27 |