Linear algebra (Gaussian elimination): JSOI2008 spherical space Generator sphere

Source: Internet
Author: User

JSOI2008 Spherical Space Generator sphere

"Title 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 Format"

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 Format"

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
Prompted


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)

Column equations, and then subtract from the adjacent two groups, eliminating two of times.

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <cmath>5 using namespacestd;6 Const intmaxn= -;7 Const Doubleeps=1e-8;8 DoubleA[MAXN][MAXN];9 Ten voidSolve (intN) { One      for(intI=1; i<=n;i++){ A         intR=i; -          for(intj=i+1; j<=n;j++) -             if(Fabs (A[j][i])-fabs (A[r][i]) >eps) r=J; the         if(r!=i) { -              for(intj=1; j<=n+1; j + +) - swap (a[i][j],a[r][j]); -         } +         Doublex=A[i][i]; -          for(intj=i;j<=n+1; j + +) a[i][j]/=x; +          for(intj=1; j<=n;j++) A             if(i!=j) { atx=A[j][i]; -                  for(intk=i;k<=n+1; k++) -a[j][k]-=a[i][k]*x; -             }     -     } - } in  - intMain () { to #ifndef Online_judge +Freopen ("bzoj_1013.in","R", stdin); -Freopen ("Bzoj_1013.out","W", stdout); the #endif *     intN; $scanf"%d",&n);Panax Notoginseng      for(intI=1; i<=n+1; i++) -          for(intj=1; j<=n;j++)     thescanf"%LF",&a[i][j]); +                  A      for(intI=1; i<=n;i++){ the          for(intj=1; j<=n;j++){ +a[i][n+1]-=a[i][j]*a[i][j]-a[i+1][j]*a[i+1][j]; -a[i][j]=2* (a[i+1][j]-a[i][j]); $         } $     }             -      - Solve (n); the      -      for(intI=1; i<=n;i++)Wuyiprintf"%.3LF", a[i][n+1]);  theprintf"\ n");  -     return 0;  Wu}

Linear algebra (Gaussian elimination): JSOI2008 spherical space Generator sphere

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.