할껀하고놀자

[백준] 16235번 나무 재테크 본문

[IT]/백준

[백준] 16235번 나무 재테크

working_hard 2019. 6. 9. 18:59
728x90
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
int dy[] = { -1,-1,-1,0,1,1,1,0 };
int dx[] = { -1,0,1,1,1,0,-1,-1 };
const int Max = 10;
int N, M, K;
int add[Max][Max];
int nutri[Max][Max];
vector<int> namu[Max][Max];

int main() {
	cin >> N >> M >> K;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> add[i][j];
			nutri[i][j] = 5;
		}
	}
	for (int i = 0; i < M; i++) {
		int y, x, age;
		cin >> y >> x >> age;
		namu[y-1][x-1].push_back(age);
	}
	for (int year = 0; year < K; year++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				sort(namu[i][j].begin(), namu[i][j].end());
				vector<int> tmp;
				int dead=0;
				for (int k = 0; k < namu[i][j].size(); k++) {
					if (namu[i][j][k] <= nutri[i][j]) {
						nutri[i][j] -= namu[i][j][k];
						tmp.push_back(namu[i][j][k] + 1);
					}
					else {
						dead += namu[i][j][k] / 2;
					}
				}
				//여름..
				nutri[i][j] += dead;
				namu[i][j] = tmp;
			}
		}
		//가을..
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < namu[i][j].size(); k++) {
					if (namu[i][j][k] % 5 == 0) {
						for (int l = 0; l < 8; l++) {
							int ny = i + dy[l];
							int nx = j + dx[l];
							if (0 <= ny && ny < N && 0 <= nx && nx < N) {
								namu[ny][nx].push_back(1);
							}
						}

					}
				}
			}
		}
		//겨울..
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				nutri[i][j] += add[i][j];
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans += namu[i][j].size();
		}
	}
	cout << ans << endl;
	return 0;
}

 

'[IT] > 백준' 카테고리의 다른 글

[백준] 14914번 사과와 바나나 나눠주기  (0) 2019.06.10
[백준] 14911번 궁합 쌍 찾기  (0) 2019.06.10
[백준] 12904번 A와 B  (0) 2019.06.08
[백준] 17176번 암호해독기  (0) 2019.06.08
[백준] 10219번 Meats On The Grill  (0) 2019.06.08
Comments