[JSOI2008] [BZOJ1013] Spherical space Generator-Gaussian elimination element

Source: Internet
Author: User

Description

There is a spherical space generator capable of producing a hard sphere in n-dimensional space. Now that you are trapped in this n-dimensional sphere, you only know the coordinates of the n+1 points on the sphere, and you need to determine the spherical coordinates of the n-dimensional sphere as quickly as you can to destroy the sphere space generator.

Input & Outputinput

The first line is an integer n (1<=n=10). The next n+1 line, each row has n real numbers, representing the n-dimensional coordinates of a point on the sphere. Each real number is accurate to 6 digits after the decimal point, and its absolute value is no more than 20000.

Output

With only one row, the n-dimensional coordinates (n real numbers) of the globe are given in turn, and two real numbers are separated by a space. Each real number is exactly 3 digits after the decimal point. Data is guaranteed to be solvable. Your answer must be the same as the standard output in order to score.

Sample

Too lazy to stick.

Solution

The calculation of space distance actually gives us some inspiration, it is advisable to set a spherical sphere, so that all stores to the spherical distance is equal, but this does not construct the matrix of the most right constant column, and the given n+1 coordinates provide help. Remove the square root of the root, and then randomly expand and then move the item, Gaussian elimination of the element. The specific equation looks at the code to understand ... Konjac konjac No code formula ...
Code:

#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include < Cmath>using std::min;using std::max;using std::swap;using std::fabs;const int maxn = 15;double DATA[MAXN][MAXN], Matrix[maxn][maxn];int n;double Pow (double x) {return x * x;}    void Gauss () {int cur;        for (int i = 1; I <= n; ++i) {cur = i; for (int j = i + 1; j <= N; ++j) fabs (Matrix[cur][i]) < Fabs (Matrix[j][i])?        cur = j:1;        for (int j = i; J <= n + 1; ++j) swap (matrix[cur][j],matrix[i][j]);        for (int j = i + 1; J <= n + 1; ++j) matrix[i][j]/= matrix[i][i];        Matrix[i][i] = 1; for (int j = i + 1, j <= N; ++j) {for (int k = i + 1; k <= n + 1; ++k) Matrix[j][k]            -= matrix[j][i] * Matrix[i][k];        Matrix[j][i] = 0; }} for (int i = n; i >= 1; i.) {for (int j = i + 1; j <= N; ++j) matrix[i][n+1]-= Matri X[I][J]* Matrix[j][n+1], matrix[i][j] = 0;        MATRIX[I][N+1]/= 1;    Matrix[i][i] = 1;    } for (int i = 1; I <= n; ++i) printf ("%.3lf", matrix[i][n+1]); Putchar (' \ n ');} void Init () {for (int i = 1, i <= N; ++i) {for (int j = 1; j <= N; ++j) Matrix[i][j] = 2 * d        ATA[I][J] + 2 * data[n+1][j];    for (int j = 1; j <= N; ++j) matrix[i][n+1] + = POW (data[n+1][j])-POW (data[i][j]);    }}int Main () {scanf ("%d", &n);    for (int i = 1; I <= n + 1; ++i) for (int j = 1; j <= N; ++j) scanf ("%lf", &data[i][j]);    Init ();    Gauss (); return 0;}

[jsoi2008][bzoj1013] Spherical space Generator-Gaussian elimination element

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.