https://www.acmicpc.net/problem/20056
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 51;
vector<int> map[MAX][MAX];
int n, m, k;
struct fireball { int r, c, m, s, d; };
vector<fireball> fb;
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 MoveFireBall() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
map[i][j].clear();
}
}
for (int i = 0; i < fb.size(); i++) {
int movei = fb[i].r + mv[fb[i].d].x * fb[i].s;
int movej = fb[i].c + mv[fb[i].d].y * fb[i].s;
while (movei > n) movei -= n;
while (movei <= 0) movei += n;
while (movej > n) movej -= n;
while (movej <= 0) movej += n;
if (movei == 0) movei = n;
else if (movei == n + 1) movei = 1;
if (movej == 0) movej = n;
else if (movej == n + 1) movej = 1;
fb[i].r = movei;
fb[i].c = movej;
map[movei][movej].push_back(i);
}
}
void CheckFireball() {
vector<fireball> fb_temp;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (map[i][j].size() > 1) {
//4개로 나누기
int weight = 0, fast = 0, num = 0;
int dir = fb[map[i][j][0]].d % 2;
bool flag = true;
for (int k = 0; k < map[i][j].size(); k++) {
num += 1;
weight += fb[map[i][j][k]].m;
fast += fb[map[i][j][k]].s;
if (dir != fb[map[i][j][k]].d % 2)
flag = false;
}
weight = weight / 5;
fast = fast / num;
if (weight > 0) {
if (flag == true) {
//다 짝수 또는 다 홀수
fb_temp.push_back({ i,j,weight,fast,0 });
fb_temp.push_back({ i,j,weight,fast,2 });
fb_temp.push_back({ i,j,weight,fast,4 });
fb_temp.push_back({ i,j,weight,fast,6 });
}
else {
fb_temp.push_back({ i,j,weight,fast,1 });
fb_temp.push_back({ i,j,weight,fast,3 });
fb_temp.push_back({ i,j,weight,fast,5 });
fb_temp.push_back({ i,j,weight,fast,7 });
}
}
}
else if (map[i][j].size() == 1)
fb_temp.push_back(fb[map[i][j][0]]);
}
}
fb = fb_temp;
}
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;
fb.push_back({ r, c, m, s, d });
}
for (int i = 0; i < k; i++) {
MoveFireBall();
CheckFireball();
}
for (int i = 0; i < fb.size(); i++)
answer += fb[i].m;
cout << answer << endl;
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
컨테이너 벨트 (0) | 2021.04.18 |
---|---|
청소년 상어 C++ (0) | 2021.04.17 |
낚시왕 C++ (0) | 2021.04.11 |
마법사 상어와 토네이도 C++ (0) | 2021.04.06 |
새로운 게임 2 C++ (0) | 2021.03.19 |