#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 11;
int map[MAX][MAX];
int n, m, k;
int nutrient[MAX][MAX];
vector<int> tree[MAX][MAX];
struct Move {
int x, y;
};
Move mv[8] = { {-1,-1}, {-1,0}, {-1,1}, {0,-1}, {0,1}, {1,-1}, {1,0}, {1,1} };
void treegrow() {
//string,summer
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int size = tree[i][j].size();
if (size > 0) {
int plusnutrient = 0;
int index = 0;
sort(tree[i][j].begin(), tree[i][j].end());
for (int k = 0; k < size; k++) {
if (nutrient[i][j] - tree[i][j][index] < 0) {
plusnutrient = plusnutrient + int(tree[i][j][index] / 2);
tree[i][j].erase(tree[i][j].begin() + index);
}
else {
nutrient[i][j] = nutrient[i][j] - tree[i][j][index];
tree[i][j][index]++;
index++;
}
}
nutrient[i][j] += plusnutrient;
}
}
}
// autumn , winter
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int size = tree[i][j].size();
if (size > 0) {
for (int k = 0; k < size; k++) {
if (tree[i][j][k] % 5 == 0) {
for (int grow = 0; grow < 8; grow++) {
int movei = i + mv[grow].x;
int movej = j + mv[grow].y;
if (movei >= 1 && movei <= n && movej >= 1 && movej <= n)
tree[movei][movej].push_back(1);
}
}
}
}
nutrient[i][j] += map[i][j];
}
}
}
int main(void) {
int answer = 0;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> map[i][j];
nutrient[i][j] = 5;
}
}
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
tree[a][b].push_back(c);
}
for (int i = 0; i < k; i++) {
treegrow();
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
answer += tree[i][j].size();
}
}
cout << answer << endl;
return 0;
}
'백준 알고리즘 > 시뮬레이션' 카테고리의 다른 글
백준 이차원 배열과 연산 C++ (0) | 2019.10.17 |
---|---|
백준 낚시왕 C++ (0) | 2019.10.17 |
백준 큐빙 C++ (0) | 2019.10.15 |
백준 1152번 C++ (0) | 2019.08.30 |
백준 1551번 C++ (0) | 2019.08.30 |