꿀잼문제
삼성은 요런 문제가 많이 나오는 것 같다. 나중에 다시 한번 풀어보자. 계절을 하나로 합쳤는데, spring, summer, fall, winter의 함수로 나누어서 한번 더 풀어봐야겠다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
int map[11][11];
vector<int> tree[11][11];
int baby[11][11];
int yang[11][11];
int n, m, k;
int dx[8] = { -1,-1,-1,0,0,1,1,1 };
int dy[8] = { -1,0,1,-1,1,-1,0,1 };
int main() {
//freopen("in1.txt", "rt" ,stdin);
int q,w,e;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> yang[i][j];
map[i][j] = 5;
}
}
for (int i = 1; i <= m; i++) {
cin >> q >> w >> e;
tree[q][w].push_back(e);
}
while (k--) {
memset(baby, 0, sizeof(baby));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
vector<int> tmp;
int dead = 0;
sort(tree[i][j].begin(), tree[i][j].end());
for (int k = 0; k < tree[i][j].size(); k++) {
if (tree[i][j][k] <= map[i][j]) {
map[i][j] -= tree[i][j][k];
tmp.push_back(tree[i][j][k] + 1);
if ((tree[i][j][k] + 1) % 5 == 0) {
for (int p = 0; p < 8; p++) {
int xx = i + dx[p];
int yy = j + dy[p];
if (xx > n || xx <= 0 || yy > n || yy <= 0) continue;
baby[xx][yy]++;
}
}
}
else dead += tree[i][j][k] / 2;
}
tree[i][j] = tmp;
map[i][j] += dead;
map[i][j] += yang[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (baby[i][j] > 0) {
for (int s = 0; s < baby[i][j]; s++) {
tree[i][j].push_back(1);
}
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (tree[i][j].size()) ans += tree[i][j].size();
}
}
cout << ans << '\n';
return 0;
}