2168KB, 4ms
연결된 map 로직
- 단순 구현 문제
- move_cloud
- 구름 이동 및 비 내리고, 구름 사라지기까지
- 구름 사라지는 과정에서는 queue에 또다시 추가를 해서 물복사 버그를 할 수 있게 함
- 연결된 map
- make_cloud
- 물복사 버그, 구름 생성까지
- queue에 있는 위치의 대각선을 보고 물복사 버그
- bool 배열을 통해 물복사 버그가 일어난 곳 표시
- move_cloud
- 주의점
- map이 연결되어 있음
- 상하좌우대각선 이동
#include <iostream>
#include <queue>
#define MAX 51
using namespace std;
int N, M, map[MAX][MAX] = {};
int di, si;
queue<pair<int, int>> q;
int dy[9] = { 0,0,-1,-1,-1,0,1,1,1 };
int dx[9] = { 0,-1,-1,0,1,1,1,0,-1 };
void input() {
cin >> N >> M;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
cin >> map[i][j];
}
void move_cloud() {
int qsize = q.size();
int y, x;
while (qsize--) {
y = q.front().first + dy[di] * si;
x = q.front().second + dx[di] * si;
q.pop();
while (y <= 0) y += N;
while (x <= 0) x += N;
while (y > N) y -= N;
while (x > N) x -= N;
map[y][x]++;
q.push({ y,x });
}
}
void make_cloud() {
bool cloud[MAX][MAX] = {};
int y, x;
while (!q.empty()) {
y = q.front().first;
x = q.front().second;
q.pop();
cloud[y][x] = true;
// 2,4,6,8
int cnt = 0;
for (int i = 2; i <= 8; i += 2) {
if (y + dy[i] > N || y + dy[i] <= 0
|| x + dx[i] > N || x + dx[i] <= 0) continue;
if (map[y + dy[i]][x + dx[i]] > 0) cnt++;
}
map[y][x] += cnt;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (cloud[i][j] || map[i][j] < 2) continue;
q.push({ i,j });
map[i][j] -= 2;
}
}
}
void solve() {
q.push({ N,1 });
q.push({ N, 2 });
q.push({ N - 1, 1 });
q.push({ N - 1,2 });
while (M--) {
cin >> di >> si;
move_cloud();
make_cloud();
}
}
void result() {
int res = 0;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
res += map[i][j];
cout << res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
input();
solve();
result();
}
e
'coding > baekjoon_codingstudy' 카테고리의 다른 글
20058 마법사 상어와 파이어스톰 (0) | 2022.10.12 |
---|---|
21608 상어 초등학교 (0) | 2022.10.11 |
20057 마법사 상어와 토네이도 (0) | 2022.10.10 |
17825 주사위 윷놀이 (0) | 2022.10.10 |
20061 모노미노도미노2 (0) | 2022.10.06 |