[bzoj1013] [JSOI2008] Spherical space generator sphere-[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're trapped in this n-dimensional sphere, you only know the ball.
The coordinates of the n+1 points on the surface, 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 (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 exactly the decimal point.
6 bits, and the 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 accurate to the decimal point
After 3 bits. 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

Tip: Give two definitions: 1, Sphere: points that are equal to any point on the sphere. 2, Distance: Set two n for space on the point A, B

Coordinates for (A1, A2, ..., an), (B1, B2, ..., bn), the distance of AB is defined as: dist = sqrt ((A1-B1) ^2 + (A2-B2) ^2 +

... + (AN-BN) ^2)

This is a Gaussian elimination of the template problem, we have a n+1 point, set the coordinates of the sphere (X1,X2,X3......,XN) so every point to its distance should be equal, so we can get n+1 nonlinear equation

then, using n+1 nonlinear equations, each nonlinear equation except 1 can get a linear equation by subtracting the first nonlinear equation, so that we have an n linearthen move the constant term to the other side of the equal sign to list the determinant using Gaussian elimination. On the Code
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5 #defineEPS 1e-66 using namespacestd;7 intN;8 structMatrix9 {Ten     Doubled[ the]; One}s[ the],a[ the]; A Doubleans[ the]; - voidWAPs (intXinty) - { the matrix tmp; -tmp=A[x]; -a[x]=A[y]; -a[y]=tmp; + } - DoubleAsbDoublex) + { A     if(x<0)return-x; at     returnx; - } - voidGauss () - { -      for(intI=1, col=1; i<=n;++i) -     { in         intp=i; -          for(intj=i+1; j<=n;++j) to         { +             if(ASB (A[j].d[col])-ASB (A[p].d[col]) >EPS) -             { thep=J; *             } $         }Panax Notoginseng         if(p!=i) - WAPs (p,i); the         if(a[i].d[col]==0) +         { Acol++; thei--; +             Continue; -         } $          for(intj=i+1; j<=n;++j) $         { -             Doublenow=a[i].d[col]/A[j].d[col]; -              for(intk=col;k<=n+1;++k) the             { -a[j].d[k]*=now,a[j].d[k]-=A[i].d[k];Wuyi             } the         } -col++; Wu     } - } About voidGet_ans () $ { -      for(intI=n;i>0;--i) -     { -      for(intj=n;j>i;--j) A     { +a[i].d[n+1]-=a[i].d[j]*Ans[j]; the     } -ans[i]=a[i].d[n+1]/A[i].d[i]; $     } the      for(intI=1; i<n;++i) the     { theprintf"%.3LF", Ans[i]); the     } -printf"%.3LF", Ans[n]); in } the intMain () the { Aboutscanf"%d",&n); the      for(intI=0; i<=n;++i) the      for(intj=1; j<=n;++j) the     { +scanf"%LF",&s[i].d[j]); -     } the      for(intI=1; i<=n;++i)Bayi      for(intj=1; j<=n;++j) the     { thea[i].d[j]=2*s[i].d[j]-2*s[0].d[j]; -a[i].d[n+1]+=s[i].d[j]*s[i].d[j]-s[0].d[j]*s[0].d[j]; -     } the Gauss (); the Get_ans (); the     return 0; the}
Spherical Space Generator

[bzoj1013] [JSOI2008] Spherical space generator sphere-[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.