TLE.
This commit is contained in:
@@ -64,8 +64,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Readin\n");
|
// printf("Readin\n");
|
||||||
output();
|
// output();
|
||||||
|
|
||||||
for (int col = 0; col < n; col++) {
|
for (int col = 0; col < n; col++) {
|
||||||
double diag_elem = get_content(col, col);
|
double diag_elem = get_content(col, col);
|
||||||
@@ -74,7 +74,7 @@ int main() {
|
|||||||
double base = get_content(row, col);
|
double base = get_content(row, col);
|
||||||
if (base != 0) {
|
if (base != 0) {
|
||||||
double coefficient = base / diag_elem;
|
double coefficient = base / diag_elem;
|
||||||
set_content(row, col, coefficient);
|
set_content(row, col, -coefficient);
|
||||||
for (int l = col + 1; l < n; l++) {
|
for (int l = col + 1; l < n; l++) {
|
||||||
set_content(row, l, get_content(row, l) - coefficient * get_content(col, l));
|
set_content(row, l, get_content(row, l) - coefficient * get_content(col, l));
|
||||||
}
|
}
|
||||||
@@ -82,18 +82,19 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("L ready\n");
|
// printf("L ready\n");
|
||||||
output();
|
// output();
|
||||||
|
|
||||||
for (int row = 0; row < n; row++) {
|
for (int row = 0; row < n; row++) {
|
||||||
set_content(row, row, 1 / get_content(row, row));
|
double diag_elem = get_content(row, row);
|
||||||
|
set_content(row, row, 1 / diag_elem);
|
||||||
for (int col = row + 1; col < n; col++) {
|
for (int col = row + 1; col < n; col++) {
|
||||||
set_content(row, col, -get_content(row, col));
|
set_content(row, col, -get_content(row, col) / diag_elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("All ready\n");
|
// printf("All ready\n");
|
||||||
output();
|
// output();
|
||||||
|
|
||||||
for (int i = 0; i < m; i++) {
|
for (int i = 0; i < m; i++) {
|
||||||
// read in one col of z
|
// read in one col of z
|
||||||
@@ -101,42 +102,46 @@ int main() {
|
|||||||
scanf("%lf", &Z[j]);
|
scanf("%lf", &Z[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Readin\n");
|
// printf("Readin\n");
|
||||||
outputZ();
|
// outputZ();
|
||||||
|
|
||||||
// calculate Z = L-1 * Z
|
// calculate Z = L-1 * Z
|
||||||
|
// do this column by column
|
||||||
for (int j = 0; j < n; j++) {
|
for (int j = 0; j < n; j++) {
|
||||||
// diag of U is always 1, z[j] * U[j][j] = z[j], so k doesn't have to equal to j
|
// diag of U is always 1, z[j] * U[j][j] = z[j], so k doesn't have to equal to j
|
||||||
for (int k = 0; k < j; k++) {
|
for (int k = j + 1; k < n; k++) {
|
||||||
Z[j] += Z[k] * get_content(j, k);
|
Z[k] += Z[j] * get_content(k, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("L-1 * Z\n");
|
// printf("L-1 * Z\n");
|
||||||
outputZ();
|
// outputZ();
|
||||||
|
|
||||||
// calculate Z = D-1 * Z
|
// calculate Z = D-1 * Z
|
||||||
for (int j = 0; j < n; j++) {
|
for (int j = 0; j < n; j++) {
|
||||||
Z[j] = Z[j] * get_content(j, j);
|
Z[j] = Z[j] * get_content(j, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("D-1 L-1 * Z\n");
|
// printf("D-1 L-1 * Z\n");
|
||||||
outputZ();
|
// outputZ();
|
||||||
|
|
||||||
// calculate Z = U-1 * Z
|
// calculate Z = U-1 * Z
|
||||||
for (int j = 0; j < n; j++) {
|
// do this column by column
|
||||||
|
// printf("Starting U-1\n");
|
||||||
|
for (int j = n - 1; j >= 0; j--) {
|
||||||
// diag of U is always 1, z[j] * U[j][j] = z[j], so k doesn't have to equal to j
|
// diag of U is always 1, z[j] * U[j][j] = z[j], so k doesn't have to equal to j
|
||||||
for (int k = j + 1; k < n; k++) {
|
for (int k = 0; k < j; k++) {
|
||||||
Z[j] += Z[k] * get_content(j, k);
|
Z[k] += Z[j] * get_content(k, j);
|
||||||
}
|
}
|
||||||
|
// outputZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("U-1 D-1 L-1 * Z\n");
|
// printf("U-1 D-1 L-1 * Z\n");
|
||||||
outputZ();
|
// outputZ();
|
||||||
|
|
||||||
// output
|
// output
|
||||||
for (int j = 0; j < n; j++) {
|
for (int j = 0; j < n; j++) {
|
||||||
printf("%lf ", Z[j]);
|
printf("%.4lf ", Z[j]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user