#include <iostream>
#include <vector>
using namespace std;
const int MAX = 55;
int n, m, k;
struct shark { int m, s, d; };
vector<shark> map[MAX][MAX];
struct MOVE { int x, y; };
MOVE mv[8] = { {-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1} };
void MoveFire() {
vector<shark> tmp[MAX][MAX];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
int sz = map[i][j].size();
if (sz>0) {
for (int z = 0; z < sz; z++) {
int d = map[i][j][z].d;
int s = map[i][j][z].s;
int m = map[i][j][z].m;
int movei = i + mv[d].x * s;
int movej = j + mv[d].y * s;
while (movei > n) movei -= n;
while (movei <= 0) movei += n;
while (movej > n) movej -= n;
while (movej <= 0) movej += n;
tmp[movei][movej].push_back({ m,s,d });
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
map[i][j] = tmp[i][j];
}
}
}
void DivideFire() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (map[i][j].size() >= 2) {
vector<shark> s_tmp;
int m = 0;
int s = 0;
int d = map[i][j][0].d % 2;
bool flag = true; //짝수
for (int z = 0; z < map[i][j].size(); z++) {
m += map[i][j][z].m;
s += map[i][j][z].s;
if (d != map[i][j][z].d % 2) {
flag = false;
}
}
m = m / 5;
if (m == 0) {
map[i][j].clear();
continue;
}
s = s / map[i][j].size();
map[i][j].clear();
if (flag == true) {
map[i][j].push_back({ m,s,0 });
map[i][j].push_back({ m,s,2 });
map[i][j].push_back({ m,s,4 });
map[i][j].push_back({ m,s,6 });
}
else {
map[i][j].push_back({ m,s,1 });
map[i][j].push_back({ m,s,3 });
map[i][j].push_back({ m,s,5 });
map[i][j].push_back({ m,s,7 });
}
}
}
}
}
int main(void) {
int answer = 0;
cin >> n >> m >> k;
for (int i = 0; i < m; i++) {
int r, c, m, s, d;
cin >> r >> c >> m >> s >> d;
map[r][c].push_back({ m,s,d });
}
for (int i = 0; i < k; i++) {
MoveFire();
DivideFire();
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (map[i][j].size() > 0) {
for(int z=0; z<map[i][j].size(); z++)
answer += map[i][j][z].m;
}
}
}
cout << answer << endl;
}
https://www.acmicpc.net/problem/20056
'백준 알고리즘 > 구현' 카테고리의 다른 글
어른 상어 C++ (0) | 2021.10.13 |
---|---|
컨베이어 벨트 위의 로봇 (0) | 2021.10.12 |
마법사 상어와 토네이도 C++ (0) | 2021.09.30 |
상어 초등학교 C++ (0) | 2021.09.18 |
마법사 상어와 블리자드 C++ (0) | 2021.09.18 |