From 5630c415c926e36ef082dbc53ce603bec89ab487 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 9 May 2022 15:26:49 +0800 Subject: [PATCH] =?UTF-8?q?P4035=20[JSOI2008]=E7=90=83=E5=BD=A2=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E4=BA=A7=E7=94=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/75423418 --- Luogu/P4035/P4035.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Luogu/P4035/P4035.cpp diff --git a/Luogu/P4035/P4035.cpp b/Luogu/P4035/P4035.cpp new file mode 100644 index 00000000..8ee06aef --- /dev/null +++ b/Luogu/P4035/P4035.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 15; +const double eps = 1e-6; + +int n; +double a[N][N], b[N][N]; + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + for (int i = 1; i <= n + 1; i++) { + for (int j = 1; j <= n; j++) { + cin >> a[i][j]; + } + } + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + b[i][j] = 2.0 * (a[i][j] - a[i + 1][j]); + b[i][n + 1] += std::pow(a[i][j], 2) - std::pow(a[i + 1][j], 2); + } + } + + for (int i = 1; i <= n; i++) { + for (int j = i; j <= n; j++) { + if (std::abs(b[j][i]) > eps) { + std::swap(b[i], b[j]); + } + } + + for (int j = 1; j <= n; j++) { + if (i == j) continue; + double x = b[j][i] / b[i][i]; + for (int k = i; k <= n + 1; k++) { + b[j][k] -= b[i][k] * x; + } + } + } + + for (int i = 1; i <= n; i++) { + cout << std::fixed << std::setprecision(3) << b[i][n + 1] / b[i][i] << ' '; + } + cout << endl; + + return 0; +}