https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRFInKex8DFAUo
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int MAX = 4001;
int n;
int map[MAX][MAX];
struct INFO { int x, y, k, dir; bool alive; };
vector<INFO> v;
struct MOVE { int x, y; };
MOVE mv[4] = { { 1,0 },{ -1,0 },{ 0,-1 },{ 0,1 } };
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int testcase;
cin >> testcase;
int index = 1;
memset(map, 0, sizeof(map));
for (; testcase > 0; testcase--) {
int answer = 0;
cin >> n;
v.clear();
memset(map, 0, sizeof(map));
for (int i = 0; i < n; i++) {
int x, y, k, dir;
cin >> x >> y >> dir >> k;
x = (x + 1000) * 2;
y = (y + 1000) * 2;
v.push_back({ y,x,k,dir,true });
map[y][x] = 1;
}
bool flag = true;
while (flag) {
flag = false;
for (int i = 0; i < v.size(); i++) {
if (v[i].alive == false) continue;
int movei = v[i].x + mv[v[i].dir].x;
int movej = v[i].y + mv[v[i].dir].y;
if (!(movei >= 0 && movei < MAX && movej >= 0 && movej < MAX)) {
v[i].alive = false;
map[v[i].x][v[i].y] -= 1;
continue;
}
map[v[i].x][v[i].y] -= 1;
map[movei][movej] += 1;
v[i] = { movei,movej,v[i].k,v[i].dir,true };
flag = true;
}
if (flag == false) break;
for (int k = 0; k < v.size(); k++) {
if (map[v[k].x][v[k].y]> 1) {
for (int kk = 0; kk < v.size(); kk++) {
if (v[kk].alive == true && v[kk].x == v[k].x && v[kk].y == v[k].y) {
answer += v[kk].k;
v[kk].alive = false;
}
}
map[v[k].x][v[k].y] = 0;
}
}
}
cout << "#" << index << " " << answer << "\n";
index++;
}
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
등산로 조성 C++ (0) | 2022.04.29 |
---|---|
탈주범 검거 C++ (0) | 2022.04.28 |
점심 식사시간 C++ (0) | 2022.04.25 |
미생물 격리 C++ (0) | 2022.04.25 |
무선 충전 C++ (0) | 2022.04.25 |