Pagini recente » Cod sursa (job #2271096) | Cod sursa (job #1414703)
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fs first
#define sc second
#define pob pop_back
#define pub push_back
#define eps 1E-7
#define sz(a) a.size()
#define count_one __builtin_popcount;
#define count_onell __builtin_popcountll;
#define fastIO ios_base::sync_with_stdio(false)
#define PI (acos(-1.0))
#define linf (1LL<<62)//>4e18
#define inf (0x7f7f7f7f)//>2e9
#ifndef ONLINE_JUDGE
ifstream fin("gauss.in");
ofstream fout("gauss.out");
#endif
const int MAXN = 310;
int n, m;
double a[MAXN][MAXN], x[MAXN];
void read() {
fin >> n >> m;
for(int j = 0; j < n; ++j)
for(int i = 0; i <= m; ++i)
fin >> a[j][i];
}
void gauss() {
int i, j, k, u;
i = j = 0;
while(i < n && j < m) {
for(k = i; k < n; ++k)
if(a[k][j] > eps || a[k][j] < -eps)
break;
if(k == n) {
++j;
continue;
}
if(k != i) {
swap(a[i], a[k]);
}
for(k = j + 1; k <= m; ++k)
a[i][k] = a[i][k] / a[i][j];
a[i][j] = 1;
for(u = i + 1; u < n; ++u) {
for(k = j + 1; k <= m; ++k)
a[u][k] -= a[u][j] * a[i][k];
a[u][j] = 0;
}
++i, ++j;
}
for(i = n - 1; i >= 0; --i) {
for(j = 0; j <= m; ++j)
if(abs(a[i][j]) > eps) {
if(j == m) {
cout << "Imposibil\n";
return;
}
x[j] = a[i][m];
for(k = j + 1; k < m; ++k)
x[j] -= x[k] * a[i][k];
break;
}
}
for(i = 0; i < m; ++i)
fout << fixed << setprecision(10) << x[i] << " ";
fout << "\n";
}
int main() {
read();
gauss();
return 0;
}