-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1022.cpp
66 lines (59 loc) · 1.41 KB
/
1022.cpp
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
//
// Created by kdongha on 2019/12/04.
//
#include <bits/stdc++.h>
int r1, c1, r2, c2;
int map[55][55];
void fill() {
for (int i = r1; i <= r2; i++) {
for (int j = c1; j <= c2; j++) {
if (i >= j) {
int max = std::max(std::abs(i), std::abs(j));
map[i - r1][j - c1] = (2 * max + 1) * (2 * max + 1) - 2 * max + i + j;
} else {
int max = std::max(std::abs(i), std::abs(j));
map[i - r1][j - c1] = 4 * max * max + 1 - 2 * max - i - j;
}
}
}
}
int find() {
int max = 0;
for (int i = 0; i <= r2 - r1; i++) {
for (int j = 0; j <= c2 - c1; j++) {
int len = 0;
int num = map[i][j];
if (num < 0) {
len++;
num = -num;
}
while (num) {
len++;
num /= 10;
}
max = std::max(max, len);
}
}
return max;
}
void print(int len) {
for (int i = 0; i <= r2 - r1; i++) {
for (int j = 0; j <= c2 - c1; j++) {
std::cout << std::setw(len) << map[i][j] << " ";
}
std::cout << "\n";
}
}
void solve() {
std::cin >> r1 >> c1 >> r2 >> c2;
fill();
int len = find();
print(len);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
solve();
return 0;
}