Rex_Cat @ 2024-08-05 16:41:58
RT
#include <bits/stdc++.h>
#define ld long double
using namespace std;
#define R_ char y_y
#define rint int
#define tam cerr << 1e3 * clock ( ) / CLOCKS_PER_SEC << 'm' << 's' << ' ' << fabs( &y_y - &x_x ) / 1024.0 / 1024.0 << 'M' << 'B' << '\n' , 0
char x_x;
const int N = 100 + 5;
const ld eps = 1e-9;
// char buf[ 1 << 23 ] , *p1 = buf , *p2 = buf , obuf[ 1 << 23 ] , *O = obuf;
// #define getchar() ( p1 == p2 && ( p2 = ( p1 = buf ) + fread( buf , 1 , 1 << 21 , stdin ) , p1 == p2 ) ? EOF : *p1 ++ )
template < class T >
inline void read ( T & s )
{
s = 0;
bool q = false;
char c = getchar ( );
while ( ! isdigit ( c ) ) { if (c == '-') q = true; c = getchar ( ); }
while ( isdigit (c) ) { s = ( s << 1 ) + ( s << 3 ) + ( c ^ 48 ); c = getchar ( ); }
if ( q ) s = -s;
}
template < class T , class ...Args >
inline void read ( T &s , Args &...x ) { read ( s ) , read ( x... ); }
#define pc putchar
template <class S>
inline void print ( S x )
{
stack < char > s;
if ( x == 0 ) return pc ( '0' ) , pc ( ' ' ) , void ();
if ( x < 0 ) x = - x , pc ( '-' );
while ( x ) { s. push ( x % 10 + 48 ) , x /= 10; }
while ( ! s. empty () ) pc ( s. top () ) , s. pop ();
putchar ( ' ' );
}
template <class S , class ...Args>
inline void print ( S x , Args ...y ) { print ( x ) , print ( y ... ); }
template <class S>
inline void Debug ( S x )
{
cerr << x << ' ';
}
template <class S , class ...Args>
inline void Debug ( S x , Args ...y ) { Debug ( x ) , Debug ( y ... ); }
#undef pc
#define endl putchar ( '\n' )
#define Endl cerr << '\n'
ld a[ N ][ N ];
int n;
stack < ld > st;
ld b[ N ];
R_; signed main ()
{
cin. tie () -> ios :: sync_with_stdio ( 0 );
cin >> n;
for ( rint i = 1 ; i <= n ; i ++ )
for ( rint j = 1 ; j <= n + 1 ; j ++ )
cin >> a[ i ][ j ];
int rt = 1;
for ( rint i = 1 ; i <= n ; i ++ )
{
rint pos = rt;
for ( rint j = i + 1 ; j <= n ; j ++ )
if ( fabs ( a[ pos ][ i ] ) - fabs ( a[ j ][ i ] ) < - eps )
pos = j;
if ( fabs ( a[ pos ][ i ] ) < eps )
continue;
for ( rint j = 1 ; j <= n + 1 ; j ++ )
swap ( a[ rt ][ j ] , a[ pos ][ j ] );
for ( rint j = rt + 1 ; j <= n ; j ++ )
{
long double x = - a[ j ][ i ] * 1.00 / a[ rt ][ i ];
for ( rint k = i ; k <= n + 1 ; k ++ )
a[ j ][ k ] += x * a[ rt ][ k ];
}
rt ++;
}
// for ( rint i = 1 ; i <= n ; i ++ )
// {
// for ( rint j = 1 ; j <= n + 1 ; j ++ )
// {
// Debug ( a[ i ][ j ] );
// }
// Endl;
// }
for ( rint i = 1 ; i <= n ; i ++ )
{
bool vis = 1;
for ( rint j = 1 ; j <= n ; j ++ )
vis &= ( fabs ( a[ i ][ j ] ) < eps );
if ( vis )
{
if ( fabs ( a[ i ][ n + 1 ] ) > eps ) { print ( -1 ); return 0; }
else { print ( 0 ); return 0; }
}
}
for ( rint i = n ; i >= 1 ; i -- )
{
for ( rint j = i + 1 ; j <= n ; j ++ )
{
a[ i ][ n + 1 ] -= b[ j ] * a[ i ][ j ];
a[ i ][ j ] = 0;
}
b[ i ] = a[ i ][ n + 1 ] / a[ i ][ i ];
if ( b[ i ] > 1e9 ) { print ( -1 ); return 0; }
}
for ( rint i = 1 ; i <= n ; i ++ )
printf ( "x%d=%.2Lf\n" , i , b[ i ] );
// return tam;
return 0;
yxy:;
puts ( "0" );
return 0;
}
by Rex_Cat @ 2024-08-05 16:48:01
@General0826