Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxn = 20;
- const double eps = 1e-5;
- int n, b[maxn];
- valarray<double> a[maxn];
- void gauss() {
- for (int col = 0; col < n; ++col) {
- int mx = col;
- for (int row = col; row < n; ++row) {
- if (a[row][col] > a[mx][col]) {
- mx = row;
- }
- }
- swap(a[mx], a[col]);
- for (int row = col + 1; row < n; ++row) {
- double cf = a[row][col] / a[col][col];
- a[row] -= cf * a[col];
- }
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr), cout.tie(nullptr);
- cout << setprecision(10) << fixed;
- cin >> n;
- for (int i = 0; i < n; ++i) {
- a[i].resize(n + 1);
- for (int j = 0, x; j <= n; ++j) {
- cin >> a[i][j];
- }
- }
- gauss();
- for (int row = 0; row < n; ++row) {
- bool check_eq = true;
- for (int col = row; col < n; ++col) {
- if (abs(a[row][col]) > eps) {
- check_eq = false;
- }
- }
- if (check_eq) {
- cout << (abs(a[row][n]) < eps ? "infinity" : "impossible") << endl;
- }
- }
- cout << "single\n";
- for (int row = n - 1; row >= 0; --row) {
- for (int col = n - 1; col >= row + 1; --col) {
- a[row][n] -= a[row][col] * a[col][n];
- }
- a[row][n] /= a[row][row];
- }
- for (int i = 0; i < n; ++i) {
- cout << a[i][n] << ' ';
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement