https://www.acmicpc.net/problem/20057
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 505;
int map[MAX][MAX];
int n;
int answer = 0;
struct MOVE { int x, y; };
MOVE mv[4] = { { 0,-1 },{ 1,0 },{ 0,1 },{ -1,0 } };
struct INFO { int x, y, v; };
int v_left[10][3] = { { -2,0,2 },{ -1,-1,10 },{ -1,0,7 },{ -1,1,1 },{ 0,-2,5 },{ 1,-1,10 },{ 1,0,7 },{ 1,1,1 },{ 2,0,2 },{ 0,-1,-1 } };
int v_down[10][3] = { { -1,-1,1 },{ -1,1,1 },{ 0,-2,2 },{ 0,-1,7 },{ 0,1,7 },{ 0,2,2 },{ 1,-1,10 },{ 1,1,10 },{ 2,0,5 },{ 1,0,-1 } };
int v_right[10][3] = { { -2,0,2 },{ -1,-1,1 },{ -1,0,7 },{ -1,1,10 },{ 0,2,5 },{ 1,-1,1 },{ 1,0,7 },{ 1,1,10 },{ 2,0,2 },{ 0,1,-1 } };
int v_up[10][3] = { { -2,0,5 },{ -1,-1,10 },{ -1,1,10 },{ 0,-2,2 },{ 0,-1,7 },{ 0,1,7 },{ 0,2,2 },{ 1,-1,1 },{ 1,1,1 },{ -1,0,-1 } };
void printmap() {
cout << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << map[i][j] << " ";
}
cout << endl;
}
}
void MoveWind(int mi, int mj, int d, int way[10][3]) {
int value = map[mi][mj];
int left = value;
for (int i = 0; i < 9; i++) {
int movei = mi + way[i][0];
int movej = mj + way[i][1];
int tmp = value * way[i][2]/100;
left -= tmp;
if (!(movei >= 0 && movei < n && movej >= 0 && movej < n)) {
answer += tmp;
}
else {
map[movei][movej] += tmp;
}
}
int movei = mi + way[9][0];
int movej = mj + way[9][1];
if (!(movei >= 0 && movei < n && movej >= 0 && movej < n)) {
answer += left;
}
else {
map[movei][movej] += left;
}
map[mi][mj] = 0;
//printmap();
//cout << answer << endl;
}
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> map[i][j];
}
}
int dir = 0; //0:왼, 1:아래, 2:우, 3:위
int movei = n / 2;
int movej = n / 2;
for (int count = 1; count < n; count++) {
for (int turn = 0; turn < 2; turn++) {
for (int k = 0; k < count; k++) {
movei = movei + mv[dir].x;
movej = movej + mv[dir].y;
if (dir == 0) MoveWind(movei, movej, dir, v_left);
else if (dir == 1) MoveWind(movei, movej, dir, v_down);
else if (dir == 2) MoveWind(movei, movej, dir, v_right);
else if (dir == 3) MoveWind(movei, movej, dir, v_up);
}
dir++;
if (dir == 4) dir = 0;
}
}
dir = 0;
for (int count = 0; count < n; count++) {
movei = movei + mv[dir].x;
movej = movej + mv[dir].y;
if (dir == 0) MoveWind(movei, movej, dir, v_left);
}
//printmap();
cout << answer << endl;
}
'백준 알고리즘 > 구현' 카테고리의 다른 글
스위치 켜고 끄기 (0) | 2022.03.08 |
---|---|
치즈 C++ (0) | 2022.03.07 |
마법사 상어와 비바라기 C++ (0) | 2022.02.05 |
마법사 상어와 블리자드 C++ (0) | 2022.02.03 |
어항 정리 C++ (0) | 2022.01.22 |