문제는 매우 간단하다. 매번 토네이도가 이동할 때 마다 일정한 비율로 흩날리는 함수를 토네이도가 이동할 때 마다 불러주면 된다.
말은 쉽다...
아직 구현 문제가 익숙하지 않아서 시간을 많이 잡아먹었다. 공간지각능력이 부족해서 그런지 방향을 돌리는게 머리속에 그려지지가 않아서 아이패드에 그려놓고 돌리면서 좌표를 찍었다...
#include <iostream>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int d[4][2][9] = {
{
{-2, -1, -1, -1, 0, 1, 1, 1, 2},
{0, -1, 0, 1, -2, -1, 0, 1, 0,}
},
{
{0, 1, 0, -1, 2, 1, 0, -1, 0},
{-2, -1, -1, -1, 0, 1, 1, 1, 2}
},
{
{2, 1, 1, 1, 0, -1, -1, -1, -2},
{0, 1, 0, -1, 2, 1, 0, -1, 0}
},
{
{0, -1, 0, 1, -2, -1, 0, 1, 0,},
{2, 1, 1, 1, 0, -1, -1, -1, -2}
}
};
int r[9] = {2, 10, 7, 1, 5, 10, 7, 1, 2};
int map[500][500];
int n;
void scatter(int x, int y, int direction){
if(!map[x][y]) return ;
int alpha = map[x][y];
if(map[x][y] >= 10){
for(int i = 0; i < 9; ++i){
int dx = d[direction][0][i], dy = d[direction][1][i];
int nx = dx + x, ny = dy + y;
int moved = map[x][y] * (float)r[i] / 100;
if((0 <= nx && nx < n) && (0 <= ny && ny < n)) map[nx][ny] += moved;
alpha -= moved;
}
}
int nx = x + dx[direction], ny = y + dy[direction];
if((0 <= nx && nx < n) && (0 <= ny && ny < n)) map[nx][ny] += alpha;
map[x][y] = 0;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
int ans = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
cin >> map[i][j];
ans += map[i][j];
}
}
int x = n/2, y = n/2, cnt = 0;
for(int i = 0; i < n/2; ++i){
for(int j = 0; j < 4; ++j){
if(j%2 == 0) cnt++;
for(int k = 0; k < cnt; ++k){
x += dx[j];
y += dy[j];
scatter(x, y, j);
}
}
}
for(int i = 0; i < cnt; ++i)
scatter(x, --y, 0);
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
ans -= map[i][j];
cout << ans;
}
백준 9465 스티커 혼내주기 (0) | 2021.08.02 |
---|---|
백준 1700 멀티탭 스케줄링 혼내주기 (0) | 2021.08.02 |
백준 1167, 1967 트리의 지름 혼내주기 (0) | 2021.08.02 |
백준 4803 트리 혼내주기 (0) | 2021.08.02 |
백준 1005 ACM Craft 혼내주기 (0) | 2021.08.02 |
댓글 영역