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
- 운영체제
- Four Squares
- redis
- 10026번
- FIFO paging
- 2475번
- 스프링 입문
- Operating System
- 이펙티브코틀린
- C#
- 스프링 핵심 원리
- C++
- 열혈 tcp/ip 프로그래밍
- 우아한 테크 세미나
- 우아한레디스
- Operating System.
- n타일링2
- TCP/IP
- 에러핸들링
- OS
- 윤성우 저자
- HTTP
- 열혈 TCP/IP 소켓 프로그래밍
- 김영한
- inflearn
- 토마토
- 제프리리처
- Spring
- Window-Via-c/c++
- BOJ
Archives
- Today
- Total
나의 브을로오그으
[c++] 7569번 : 토마토 본문
https://www.acmicpc.net/problem/7569
7569번: 토마토
첫 줄에는 상자의 크기를 나타내는 두 정수 M,N과 쌓아올려지는 상자의 수를 나타내는 H가 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M ≤ 100, 2 ≤ N ≤ 100,
www.acmicpc.net
#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 |