HYSBZ 1013: [JSOI2008] Spherical space generator sphere (Gaussian elimination template)

Source: Internet
Author: User

Title Link: http://www.lydsy.com/JudgeOnline/problem.php?id=1013



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

The first line is an integer, N. 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 Input2
0.0 0.0
-1.0 1.0
1.0 0.0Sample Output0.500 1.500HINT

Data size:

For 40% of data, 1<=n<=3

For 100% of data, 1<=n<=10

Tip: Give two definitions:

1, the ball sphere: to the spherical surface any point distance is equal points.

2, Distance: Set two n for Space point A, B coordinates (a1, a2, ..., an), (B1, B2, ..., BN), then AB distance is defined as: dist = sqrt ((A1-B1) ^2 + (A2-B2) ^2 + ... + (an-bn) ^2)


Ps:

Gaussian elimination!

Set the center of the circle (x, y), and then use the radius equal! Using the distance formula we can get n equations, and then use the Gaussian elimination to solve the equation!

Set the circle on a point for (a B) to get: (a-x) ^2+ (b-y) ^2 = a^2-2ax+x^2+b^2-2by+y^2;

Set the circle on a point for (A1,B1) Get: (a-x) ^2+ (b-y) ^2 = a^2-2ax+x^2+b^2-2by+y^2;

Radii equal to get:

2 (a1-a) x+2 (b1-b) y = a1^2-a^2+b1^2-b^2;

The code is as follows:

#include <cstdio> #include <cstring> #include <cmath> #include <iostream>using namespace std; int n; #define EPS 1e-9const int maxn = 220;double a[maxn][maxn],x[maxn];//equation to the left of the matrix and equation to the right of the value, after the solution x is the result int equ,var;//    The number of equations and the number of unknowns/** return 0 for no solution, 1 for the solution */int Gauss () {int i,j,k,col,max_r;        for (k=0,col=0; k<equ&&col<var; k++,col++) {max_r=k;        for (i=k+1; i<equ; i++) if (Fabs (A[i][col]) >fabs (A[max_r][col])) max_r=i;        if (Fabs (A[max_r][col]) <eps) return 0;            if (K!=max_r) {for (j=col; j<var; j + +) Swap (a[k][j],a[max_r][j]);        Swap (X[k],x[max_r]);        } X[k]/=a[k][col];        for (j=col+1; j<var; j + +) A[k][j]/=a[k][col];        A[k][col]=1;                for (i=0; i<equ; i++) if (i!=k) {x[i]-=x[k]*a[i][k];                for (j=col+1; j<var; j + +) A[i][j]-=a[k][j]*a[i][col];            a[i][col]=0; }} return 1;}    int main () {double S[MAXN];        while (~SCANF ("%d", &n)) {memset (x,0,sizeof (x));        Equ = var = n;        for (int i = 0; i < n; i++) {scanf ("%lf", &s[i]);        } double TT; for (int i = 0; i < n; i++) {for (int j = 0; J < N; j + +) {scanf ("%lf", &A                MP;TT);                A[I][J] = (tt-s[j]);            X[I]+=TT*TT-S[J]*S[J];                }} int ans = Gauss ();        printf ("%.3lf", x[0]);        for (int i = 1; i < n; i++) {printf ("%.3lf", X[i]);    } printf ("\ n"); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HYSBZ 1013: [JSOI2008] Spherical space generator sphere (Gaussian elimination template)

Related Article

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.