Bzoj 1013 [JSOI2008] Spherical space generator sphere (Gaussian elimination)

Source: Internet
Author: User

1013: [JSOI2008] spherical space generator sphere time limit:1 Sec Memory limit:162 MB
submit:3584 solved:1863
[Submit] [Status] [Discuss] 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)

Source

Ideas

Gaussian elimination element

Column equation: Set two point coordinates of a[],b[], and x[] is the spherical coordinates. is satisfied:

Each of the two adjacent points satisfies this formula to ensure that X is the sphere, so only the n equations need to be solved.

Then the Gaussian elimination equation can be solved.

Code

1#include <cstdio>2#include <cmath>3#include <iostream>4 using namespacestd;5 6typedefDoubleDL;7 Const intN = -;8 9 DL A[n][n],a[n][n];Ten intN; One  A voidGause () { -     intI,j,k,r; -      for(i=0; i<n;i++) {//eliminate Yuan theR=i; -          for(j=i+1; j<n;j++) -             if(Fabs (A[j][i]) >fabs (A[r][i]) r=J; -         if(r!=i) for(j=0; j<=n;j++) Swap (a[r][j],a[i][j]); +          for(j=n;j>=i;j--)//make A[k][i] 0 -              for(k=i+1; k<n;k++) +a[k][j]-=a[k][i]/a[i][i]*A[i][j]; A     } at      for(i=n-1; i>=0; i--) {//Back to Generation -          for(j=i+1; j<n;j++) -a[i][n]-=a[j][n]*A[i][j]; -A[i][n]/=A[i][i]; -     } - } in  - intMain () { toscanf"%d",&n); +      for(intI=0; i<=n;i++) for(intj=0; j<n;j++) -scanf"%LF",&a[i][j]); the      for(intI=0; i<n;i++) {//Tectonic equation set *          for(intj=0; j<n;j++) a[i][j]=2* (a[i+1][j]-a[i][j]); $          for(intj=0; j<n;j++) a[i][n]+=a[i+1][j]*a[i+1][j]-a[i][j]*A[i][j];Panax Notoginseng     } - Gause (); theprintf"%.3LF", a[0][n]);  +      for(intI=1; i<n;i++) printf ("%.3LF", A[i][n]); A     return 0; the}

Bzoj 1013 [JSOI2008] Spherical space generator sphere (Gaussian elimination)

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.