Still, 8 and 10 wa.

This commit is contained in:
unlockable
2023-12-26 01:50:27 +08:00
parent f24638bb8c
commit d567388476

View File

@@ -1,9 +1,10 @@
#include <stdio.h>
#include <math.h>
#define EPSILON 1e-6
double A[5051] = {0};
double point_xs[101] = {0};
double t[101] = {0};
long double t[101] = {0};
double get_num(int row, int col) {
if (col > row) {
@@ -19,7 +20,7 @@ double set_num(int row, int col, double content) {
return A[row * (row + 1) / 2 + col] = content;
}
bool compare_double(double a, double b) {
bool compare_double(long double a, long double b) {
return (a - b > 0 ? a - b : -(a - b)) < EPSILON;
}
@@ -60,31 +61,27 @@ int main() {
for (int row = 0; row < valid_point_num; row++) {
set_num(row, 0, 1);
for (int col = 1; col <= row; col++) {
set_num(row, col, point_xs[row] - point_xs[col - 1]);
set_num(row, col, get_num(row, col - 1) * (point_xs[row] - point_xs[col - 1]));
}
}
// Solve for t
int continued_zero_count = 0;
for (int row = 0; row < valid_point_num; row++) {
for (int i = 0; i < row; i++) {
t[row] /= get_num(row, i);
t[row] -= t[i];
t[row] -= t[i] * get_num(row, i);
}
if (compare_double(t[row], 0)) {
t[row] = 0;
continued_zero_count++;
}
else {
if (!compare_double(t[row], 0)) {
t[row] /= get_num(row, row);
continued_zero_count = 0;
}
else {
t[row] = 0;
}
}
// Find for highest exponent
int highest = valid_point_num - 1;
for (; highest >= 0; highest--) {
if (!compare_double(t[highest] / 10, 0)) {
if (!compare_double(t[highest], 0)) {
break;
}
}