Pagini recente » Cod sursa (job #977782) | Cod sursa (job #814994) | Cod sursa (job #613739) | Cod sursa (job #829753) | Cod sursa (job #1820018)
#include <bits/stdc++.h>
using namespace std;
typedef double f64;
const int SPQR = 305;
const f64 EPS = 1e-8;
int n, m;
int point[SPQR];
f64 ant[SPQR], gauss[SPQR][SPQR];
inline bool eq(const f64 &a, const f64 &b) {
return abs(a - b) < EPS; }
int main(void) {
freopen("gauss.in", "r", stdin);
freopen("gauss.out", "w", stdout);
int i, j, k, tmp;
f64 rat;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; ++i)
for (j = 1; j <= m + 1; ++j)
scanf("%lf", &gauss[i][j]);
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m + 1 && !point[i]; ++j) if (!eq(gauss[i][j], 0.0))
point[i] = j;
if (point[i] == 0)
continue;
if (point[i] == m + 1) {
puts("Imposibil\n");
return 0; }
for (k = 1; k <= n; ++k) if (i != k && !eq(gauss[k][point[i]], 0.0)) {
rat = gauss[k][point[i]] / gauss[i][point[i]];
for (j = 1; j <= m + 1; ++j)
gauss[k][j]-= gauss[i][j] * rat; } }
for (i = 1; i <= n; ++i)
if (point[i])
ant[point[i]] = gauss[i][m + 1] / gauss[i][point[i]];
for(i = 1; i <= m; ++i)
printf("%.10f ", ant[i]);
printf("\n");
return 0; }