概要
与えられた二元一次連立方程式を解け。
解法
ガウス・ジョルダン法(→ google:ガウス・ジョルダン法)というアルゴリズムで解けます。
コード
#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i ) #define ALL( c ) (c).begin(), (c).end() typedef vector<double> VD; typedef vector< VD > VVD; VD solve( VVD matrix ) { REP( i, 0, matrix.size() ) { double a = matrix[i][i]; REP( j, 0, matrix[i].size() ) { matrix[i][j] /= a; } REP( j, 0, matrix.size() ) { if ( i == j ) { continue; } double b = matrix[j][i]; REP( k, 0, matrix[j].size() ) { matrix[j][k] -= b * matrix[i][k]; } } } VD res; transform( ALL( matrix ), back_inserter( res ), []( VD m ){ return m.back(); } ); return res; } int main() { cin.tie( 0 ); ios::sync_with_stdio( false ); double a, b, c, d, e, f; cout.precision( 3 ); cout << fixed; while ( cin >> a >> b >> c >> d >> e >> f ) { auto res = solve( VVD{ { a, b, c }, { d, e, f } } ); cout << res[0] << ' ' << res[1] << endl; } return 0; }