Pagini recente » Cod sursa (job #2136000) | Cod sursa (job #2720611) | Cod sursa (job #2568011) | Cod sursa (job #1946486) | Cod sursa (job #3227107)
#include <algorithm>
#include <iostream>
#include <fstream>
#include <climits>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using ull = unsigned long long;
//using ll = long long;
//#define int __int128
//#define int ll
#define pii pair <int, int>
#define all(a) (a).begin(), (a).end()
#define fr first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define vt vector
#define FOR(a, b) for(int i = (a); i <= (b); i++)
#define FORr(a, b) for(int i = (a); i >= (b); i--)
#define sz(x) (int)(x).size()
#define YES cout << "YES\n"
#define NO cout << "NO\n"
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rangerng(int l, int r){
return uniform_int_distribution<>(l, r)(rng);
}
string filename = "gauss";
ifstream fin(filename + ".in");
ofstream fout(filename + ".out");
////////////////////////////////////////////////////////////////////////////////////
const int NMAX = 301;
const double EPS = 1e-11;
bool not_null(double x){
return (x < -EPS || x > EPS);
}
double coef[NMAX + 1][NMAX + 1];
double ans[NMAX + 1];
void solve(){
int n, m;
fin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m + 1; j++){
fin >> coef[i][j];
}
}
int i = 1, j = 1;
while(i <= n && j <= m){
int k = -1;
for(int l = i; l <= n; l++){
if(not_null(coef[l][j])){
k = l;
break;
}
}
if(k == -1){
j++;
continue;
}
for(int c = 1; c <= m + 1; c++){
swap(coef[k][c], coef[i][c]);
}
for(int c = m + 1; c >= j; c--){
coef[i][c] /= coef[i][j];
}
for(int l = i + 1; l <= n; l++){
for(int c = m + 1; c >= j; c--){
coef[l][c] -= coef[l][j] * coef[i][c];
}
}
i++, j++;
}
for(int l = n; l >= 1; l--){
for(int c = 1; c <= m + 1; c++){
if(not_null(coef[l][c])){
if(c == m + 1){
fout << "Imposibil\n";
exit(0);
}
ans[c] = coef[l][m + 1];
for(int k = m; k >= c + 1; k--){
ans[c] -= ans[k] * coef[l][k];
}
break;
}
}
}
fout << fixed << setprecision(10);
for(int c = 1; c <= m; c++){
fout << ans[c] << ' ';
}
fout << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int T;
//fin >> T;
T = 1;
while(T--){
solve();
}
return 0;
}
/*
*/