"JSOI2008" Spherical space generator

Source: Internet
Author: User

P2182-"JSOI2008" Spherical space generator 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 Input

2
0.0 0.0
-1.0 1.0
1.0 0.0

Sample Output

0.500 1.500

Hint

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 the space point A, B coordinates (a1, a2, ..., an), (B1, B2, ..., bn), the distance of AB is defined as:
dist = sqrt ((A1-B1) ^2 + (A2-B2) ^2 + ... + (an-bn) ^2)

Analysis x=3 The situation:
set the sphere to x, Y, radius is R . 
You can list the equations:
(a1-x) ^2+ (b1-y) ^2+ (c1-z) ^2=r^2;
(a2-x) ^2+ (b2-y) ^2+ (c2-z) ^2=r^2;
(a3-x) ^2+ (b3-y) ^2+ (c3-z) ^2=r^2;
(a4-x) ^2+ (b4-y) ^2+ (c4-z) ^2=r^2;
by simplifying each equation and subtracting equation 1 from the 2,3,4 equation, we can get 3 equations that are similar to this one:
2 (A2-A1) +2 (B2-B1) +2 (C2-C1) =a2^2-a1^2+b2^2-b1^2+c2^2-c1^2 . 
In this way, the two-time equation is reduced to one-time equation, then the Gaussian elimination method is used to solve the equation.
Gaussian elimination element method:
Put the coefficients in a matrix, and finally the matrix into this form:

1

0

0

X

0

1

0

Y

0

0

1

Z

finally x, y is the answer. 
Enumerates each column to eliminate the element.
① Select a main element:intt=i;while (!a[t][i]) t++;
② The main element to the current line. 
③ the coefficients of the principal elements into one. 
④ then the coefficients of the other equations on this column of the main element are converted to 0. (Plus and minus the elimination element method)
1#include <Set>2#include <map>3#include <queue>4#include <stack>5#include <ctime>6#include <cmath>7#include <string>8#include <vector>9#include <cstdio>Ten#include <cstdlib> One#include <cstring> A#include <iostream> -#include <algorithm> - using namespacestd; the Doublea[ the][ the],b[ the][ the]; - intN; - voidGauss () { -    for(intI=1; i<=n;i++){ +     intt=i; -      while(!b[t][i]) t++; +      for(intj=1; j<=n+1; j + +) Swap (b[i][j],b[t][j]); A     Doublek=B[i][i]; at      for(intj=i;j<=n+1; j + +) b[i][j]/=K; -      for(intj=1; j<=n;j++) -       if(J!=i &&B[j][i]) { -k=B[j][i]; -      for(intp=i;p<=n+1;p + +) -b[j][p]-=k*B[i][p]; in       } -   } to } + intMain () - { theFreopen ("!. Inch","R", stdin); *Freopen ("!. out","W", stdout); $scanf"%d",&n);Panax Notoginseng    for(intI=1; i<=n+1; i++) -      for(intj=1; j<=n;j++) thescanf"%LF",&a[i][j]); +    for(intI=2; i<=n+1; i++)//column Equation A      for(intj=1; j<=n;j++) theb[i-1][j]= (a[i][j]-a[1][J]) *2, b[i-1][n+1]+= (a[i][j]*a[i][j]-a[1][j]*a[1][j]); + Gauss (); -    for(intI=1; i<=n;i++) $printf"%.3LF", b[i][n+1]); $   return 0; -}

"JSOI2008" Spherical space generator

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.