-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path17779.cpp
More file actions
71 lines (59 loc) · 1.42 KB
/
17779.cpp
File metadata and controls
71 lines (59 loc) · 1.42 KB
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
#include<iostream>
#include<algorithm>
#include<vector>
#include <climits>
using namespace std;
int N;
int map[21][21];
int diff(int x, int y, int d1, int d2) {
vector<int> population(5, 0);
for (int r = 1; r <= N; r++) {
for (int c = 1; c <= N; c++) {
//1锅 急芭备
if (r < x + d1 && c <= y && !(r >= x && c >= y - (r - x))) {
population[0] += map[r][c];
}
//2锅 急芭备
else if (r <= x + d2 && c > y && !(r >= x && c <= y + (r - x))) {
population[1] += map[r][c];
}
//3锅 急芭备
else if (r >= x + d1 && c < y - d1 + d2 && !(r <= x + d1 + d2 && c >= (y - d1 + d2 - (x + d1 + d2 - r)))) {
population[2] += map[r][c];
}
//4锅 急芭备
else if (r > x + d2 && c >= y - d1 + d2 && !(r <= x + d1 + d2 && c <= (y - d1 + d2 + (x + d1 + d2 - r)))) {
population[3] += map[r][c];
}
//5锅 急芭备
else {
population[4] += map[r][c];
}
}
}
sort(population.begin(), population.end());
return population[4] - population[0];
}
int minDiff() {
int res = INT_MAX;
for (int x = 1; x <= N - 2; x++) {
for (int y = 2; y <= N - 1; y++) {
for (int d1 = 1; d1 <= y - 1 && d1 <= N - x - 1; d1++) {
for (int d2 = 1; d2 <= N - y && d2 <= N - x - 1; d2++) {
res = min(res, diff(x, y, d1, d2));
}
}
}
}
return res;
}
int main() {
cin >> N;
for (int x = 1; x <= N; x++) {
for (int y = 1; y <= N; y++) {
cin >> map[x][y];
}
}
cout << minDiff() << endl;
return 0;
}