#P3389. 【模板】高斯消元法

【模板】高斯消元法

Description

Given a system of linear equations, solve it.

$$\begin{cases} a_{1, 1} x_1 + a_{1, 2} x_2 + \cdots + a_{1, n} x_n = b_1 \\ a_{2, 1} x_1 + a_{2, 2} x_2 + \cdots + a_{2, n} x_n = b_2 \\ \cdots \\ a_{n,1} x_1 + a_{n, 2} x_2 + \cdots + a_{n, n} x_n = b_n \end{cases}$$

Input Format

The first line contains a positive integer nn.

Lines 22 to n+1n+1 each contain n+1n+1 integers, which are a1,a2,,an a_1, a_2, \dots ,a_n and bb, representing one equation.

Output Format

Output nn lines, one number per line. The ii-th line is xix_i (rounded to 22 decimal places).

If there is no solution or the solution is not unique, output No Solution on the first line.

3
1 3 4 5
1 4 7 3
9 3 2 2
-0.97
5.18
-2.39

Hint

This problem uses a special judge to handle cases where floating-point issues might produce -0.00. If some xix_i rounds to 0.00, then both -0.00 and 0.00 are accepted.

Constraints: $1 \leq n \leq 100, \left | a_i \right| \leq {10}^4 , \left |b \right| \leq {10}^4$. It is guaranteed that if there is a solution, then all solutions satisfy xi103|x_i|\le 10^3, and the rounded results of xi±106x_i\pm 10^{-6} and xix_i are the same (i.e., small precision errors will not change the rounded result).

Translated by ChatGPT 5