Pagini recente » Cod sursa (job #1902717) | Cod sursa (job #2367188) | Cod sursa (job #1499587) | Cod sursa (job #2959041) | Cod sursa (job #3199683)
#include <fstream>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <iomanip>
#include <algorithm>
#define int long long
#define pb push_back
#define zeros(x) ((x^(x-1))&x)
#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_p(x) cerr<<#x": "<<x.first<<","<<x.second<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
using namespace std;
ifstream cin ("gauss.in");
ofstream cout ("gauss.out");
long double a[305][305];
long double rasp[305];
long double modul(long double x)
{
if(x<0)
return -x;
return x;
}
long double eps = 1e-10;
void solve()
{
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m+1;j++)
cin >> a[i][j];
int i = 1;
int j = 1;
while(i<=n && j<=m)
{
int x = i;
while(x<=n && modul(a[x][j])<eps)
x++;
if(x>n)
{
j++;
continue;
}
swap(a[i],a[x]);
long double fact = a[i][j];
for(int y=j;y<=m+1;y++)
a[i][y] /= fact;
for(int u=i+1;u<=n;u++)
{
long double z = a[u][j]/a[i][j];
for(int w=j;w<=m+1;w++)
a[u][w]-=a[i][w]*z;
}
i++;
j++;
}
for(int i=n;i>0;i--)
for(int j=1;j<=m+1;j++)
{
if(modul(a[i][j])<eps)
continue;
if(j==m+1)
{
cout << "Imposibil";
return;
}
rasp[j] = a[i][m+1];
for(int k=j+1;k<=m;k++)
rasp[j]-= rasp[k]*a[i][k];
break;
}
for(int j=1;j<=m;j++)
cout << fixed << setprecision(15) << rasp[j] << ' ';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t)
{
t--;
solve();
}
return 0;
}