#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #define vd vector #define vvd vector > #define ui unsigned int using namespace std; inline void print(); inline double sqr(const double& a) { return a * a; } inline double coeff(const double& a, const double& b, const double& c) { return a / sqrt(sqr(b) + sqr(c)); } vd operator +(const vd& a, const vd& b) { vd ret = vd(a.size()); for (int i = 0; i < a.size(); ++i) ret[i] = a[i] + b[i]; return ret; } vd operator *(const vd& a, double d) { vd ret = vd(a.size()); for (int i = 0; i < a.size(); ++i) ret[i] = a[i] * d; return ret; } int n; vvd g; vd ans; inline void rotate(const int& ind) { for (int i = ind + 1; i < n; ++i) { double c = coeff(g[ind][ind], g[ind][ind], g[i][ind]); double s = coeff(g[i][ind], g[ind][ind], g[i][ind]); vd old_ind = g[ind]; vd old_i = g[i]; g[ind] = old_ind * c + old_i * s; g[i] = old_ind * (-s) + old_i * c; } } inline void triangle_solve() { int k = n - 1; ans.resize(n); for (int i = k; i >= 0; --i) { ans[i] = g[i][n] / g[i][i]; for (int j = i - 1; j >= 0; --j) { g[j][n] -= ans[i] * g[j][i]; g[j][i] = 0; } } cout << "solution:" << endl; for (int i = 0; i < n; ++i) cout << "x[" << i + 1 << "] " << setw(12) << fixed << setprecision(6) << ans[i] << endl; } int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n; g.resize(n, vd(n + 1)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n + 1; ++j) { cin >> g[i][j]; } } print(); for (int i = 0; i < n - 1; ++i) { rotate(i); print(); } triangle_solve(); return 0; } inline void print() { for (int i = 0; i < n; ++i) { cout << "( "; for (int j = 0; j < n; ++j) cout << setw(12) << fixed << setprecision(6) << g[i][j]; cout << " ) " << fixed << setprecision(6) << g[i][n]; cout << endl; } cout << endl; }