Pagini recente » Cod sursa (job #1429606) | Cod sursa (job #1162054) | Cod sursa (job #428891) | Cod sursa (job #387458) | Cod sursa (job #1820016)
#include <bits/stdc++.h>
using namespace std;
typedef long double f80;
const int SPQR = 305;
const f80 EPS = 1e-9;
int n, m;
int point[SPQR];
f80 ant[SPQR], gauss[SPQR][SPQR];
inline bool eq(const f80 &a, const f80 &b) {
return abs(a - b) < EPS; }
int main(void) {
freopen("gauss.in", "r", stdin);
freopen("gauss.out", "w", stdout);
int i, j, k, tmp;
f80 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.0L))
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.0L)) {
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("%.10Lf ", ant[i]);
printf("\n");
return 0; }