-
Notifications
You must be signed in to change notification settings - Fork 1
/
OJ_07.cpp
52 lines (52 loc) · 2.37 KB
/
OJ_07.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
#include <stdio.h>
#pragma warning(disable:4996)
#define M 1600
#define N 20
int main() {
int m, n;
scanf("%d %d", &m, &n);
double MainDiag[M];
double UpperDiag[M - 1];
double LowerDiag[M - 1];
double B[M][N];
for (int i = 0; i < m; i++) {
scanf("%lf", &MainDiag[i]);
}
for (int i = 0; i < m - 1; i++) {
scanf("%lf", &UpperDiag[i]);
}
for (int i = 0; i < m - 1; i++) {
scanf("%lf", &LowerDiag[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%lf", &B[j][i]);
}
}
for (int i = 0; i < m - 1; i++) {
MainDiag[i + 1] -= LowerDiag[i] / MainDiag[i] * UpperDiag[i];
for (int j = 0; j < n; j++) {
B[i + 1][j] -= LowerDiag[i] / MainDiag[i] * B[i][j];
}
LowerDiag[i] = 0.;
}
for (int i = m - 2; i >= 0; i--) {
for (int j = 0; j < n; j++) {
B[i][j] -= B[i + 1][j] * UpperDiag[i] / MainDiag[i + 1];
}
UpperDiag[i] = 0;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
B[i][j] /= MainDiag[i];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%lf", B[j][i]);
if (j < m - 1) printf(" ");
else if (i < n - 1) printf("\n");
}
}
return 0;
}