Bzoj_1013_[jsoi2008]_ Spherical Space Generator _ (Gaussian elimination Element)

Source: Internet
Author: User

Describe

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

n-dimensional space, the n-dimensional coordinates of n+1 points on the ball are given, and the coordinate of the spherical coordinates is obtained.

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)

Analysis

For the first n points, the distance from the first point to the sphere is the same as the i+1, which can be listed as follows n equations (x for the sphere):

$$\sum_{j=1}^n (a[i][j]^2-a[x][j]^2) =\sum_{j=1}^n (a[i+1][j]^2-a[x][j]^2) $$

We unfold it, simplify it, get:

$$\SUM_{J=1}^N2A[X][J] (A[i+1][j]-a[i][j]) =\sum_{j=1}^n (a[i+1][j]^2-a[i][j]^2) $$

As in the equation above \ (A[i][j] and a[i+1][j]\) are known, so is an n-ary one-time equation. We can list up to n, and the problem is transformed to find a solution to a linear equation group.

For such a problem, we gaussian elimination of the element method. In fact, we usually solve the equation of the same elimination, I think about the idea.

We set out the equations, marking them from the 1~n.

Let the 2~n equation be added to the equation of number 1th, and eliminate their 1th.

Let the 3~n equation add a certain number of equation 2nd, the number of their 2nd to eliminate.

...

Finally, it was found that the equations became a triangular shape. The n equation has only one unknown, N. The next to the next generation into the solution.

Solve the N-number into the n-1 number equation, find out the n-1 number.

The n-1 is solved by substituting the n-2 number equation, and the n-2 number is obtained.

...

This will be OK.

But in the implementation of the time we usually use what the main element elimination method ...

The meaning is to eliminate the I-element, because the I~n equation is equivalent, so we do not have to choose the I-Number equation, you can choose the other.

Which one do we choose? We choose the one with the highest absolute value of the I-element.

In this case, the other equations will be coupled with a smaller multiple of the selected equation, which will reduce the error caused by multiplication ...

It's almost like this, it's not complicated, feel it.

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= -+5;5 intN;6 DoubleA[MAXN][MAXN],A[MAXN][MAXN];7 voidGause () {8      for(intI=1; i<=n;i++){9         intt=i;Ten          for(intj=i+1; j<=n;j++)if(Fabs (A[j][i]) >fabs (A[t][i]) t=J; One         if(t!=i) for(intj=1; j<=n+1; j + +) Swap (a[i][j],a[t][j]); A          for(intj=i+1; j<=n;j++){ -             Doublex=a[j][i]/A[i][i]; -              for(intk=i;k<=n+1; k++) a[j][k]-=x*A[i][k]; the         } -     } -      for(inti=n;i>=1; i--){ -          for(intj=i+1; j<=n;j++) a[i][n+1]-=a[j][n+1]*A[i][j]; +a[i][n+1]/=A[i][i]; -     } + } A intMain () { atscanf"%d",&n); -      for(intI=1; i<=n+1; i++) for(intj=1; j<=n;j++) scanf ("%LF",&a[i][j]); -      for(intI=1; i<=n;i++){ -          for(intj=1; j<=n;j++) a[i][j]=2* (a[i+1][j]-a[i][j]); -          for(intj=1; j<=n;j++) a[i][n+1]+=a[i+1][j]*a[i+1][j]-a[i][j]*A[i][j]; -     } in Gause (); -printf"%.3LF", a[1][n+1]); to      for(intI=2; i<=n;i++) printf ("%.3LF", a[i][n+1]); +     return 0; -}
View Code

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

Source

Bzoj_1013_[jsoi2008]_ Spherical Space Generator _ (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.