1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
[[import]] java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
static int N, res;
static int[][] board;
static int[] dx = { 0, 1, 0, -1 };
static int[] dy = { -1, 0, 1, 0 };
static int[] percents = {1, 1, 2, 7, 7, 2, 10, 10, 5};
static int[][] sdx = {
{-1, 1,-2,-1, 1, 2,-1, 1, 0, 0},
{-1,-1, 0, 0, 0, 0, 1, 1, 2, 1},
{-1, 1,-2,-1, 1, 2,-1, 1, 0, 0},
{ 1, 1, 0, 0, 0, 0,-1,-1,-2,-1}
};
static int[][] sdy = {
{ 1, 1, 0, 0, 0, 0,-1,-1,-2,-1},
{-1, 1,-2,-1, 1, 2,-1, 1, 0, 0},
{-1,-1, 0, 0, 0, 0, 1, 1, 2, 1},
{-1, 1,-2,-1, 1, 2,-1, 1, 0, 0}
};
static void cal(int sr, int sc, int sdir) {
int sand = board[sr][sc];
for (int i = 0; i < 10; i++) {
int nr = sr + sdx[sdir][i];
int nc = sc + sdy[sdir][i];
if (i == 9) {
if \(nr < 0 \|| nr >= N \|| nc < 0 \|| nc >= N)
res += sand;
else
board[nr][nc] += sand;
break;
}
int cur = board[sr][sc] * percents[i] / 100;
sand -= cur;
if \(nr < 0 \|| nr >= N \|| nc < 0 \|| nc >= N)
res += cur;
else
board[nr][nc] += cur;
}
}
static void solution() {
int r = N/2, c = N/2, dir = 0;
int depth = 2, cnt = 0;
for (int level = 1; level < N * N; level++) {
r += dx[dir];
c += dy[dir];
cal(r, c, dir);
cnt++;
if (cnt >= depth/2) {
cnt = 0;
dir = (dir+1) % 4;
depth++;
}
}
}
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
res = 0;
N = Integer.parseInt(in.readLine());
board = new int[N][N];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(in.readLine(), " ");
for (int j = 0; j < N; j++)
board[i][j] = Integer.parseInt(st.nextToken());
}
solution();
System.out.println(res);
}
}
|