[luogu4035 JSOI2008] spherical space Generator (matrix Gaussian elimination Element)

Source: Internet
Author: User

Transmission Door

Title Description

There is a spherical space generator capable of producing a hard sphere in the nnn dimension space. Now that you are trapped in this nnn sphere, you only know the coordinates of the n+1n+1n+1 points on the sphere, and you need to determine the spherical coordinates of the nnn sphere as quickly as you can to destroy the sphere space generator.

Input/output format

Input format:

The first line is an integer nnn (1<=n=10) (1<=n=10) (1<=n=10). The next n+1n+1n+1 line, each line has a nnn real number, representing the nnn dimension coordinates of a point on the sphere. Each real number is accurate to 666 digits after the decimal point, and its absolute value is no more than 200002000020000.

Output format:

With only one row, the nnn coordinates of the spherical sphere (nnn real numbers) are given in turn, and the two real numbers are separated by a space. Each real number is exactly 333 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.

Input/Output sample

Input Sample # #:

2
0.0 0.0
-1.0 1.0
1.0 0.0

Sample # # of output:

0.500 1.500

Description

Tip: Give two definitions:

Exercises

The equation is constructed from two points using the distance of all points to the sphere.
For example, if you are now two-dimensional
Set the sphere to $ (x, y) $ with two points $ (a, A, B ') $
The square of the distance between the point and the sphere is
$ (a-x) ^2+ (b-y) ^2 = a^2-2ax+x^2+b^2-2by+y^2$
Subtract another point:
$ (a-a ') x+2 (b-b ') y=a^2-a ' ^2+b^2-b ' ^2$
Make a list of Gauss elimination.
Ps:
1. Use one point to contact all other points to list the equations
2. Note the boundary when writing the Gaussian elimination element

Code

by menteur_hxy#include<cstdio> #include <iostream> #include <cstring> #include <cmath># Define LL long Long#define M (A, a) memset (A, (b), sizeof (a)) #define F (I,A,B) for (register int i= (a); i<= (b); i++) #define C (i,a,b) for (register int i= (b); i>= (a); i--) using namespace std;    ll Rd () {ll x=0,fla=1; char C=getchar ();    while (!isdigit (c)) {if (c== '-') Fla=-fla;c=getchar ();}    while (IsDigit (c)) x= (x<<3) + (x<<1) +c-48,c=getchar (); return X*FLA;}    const double Eps=1e-6;const int n=11;int n;double da[n][n],a[n],ans[n];int gauss () {int h=1,l=1;        for (; h<=n&&l<=n+1;h++,l++) {int r=h;        F (I,h+1,n) if (Fabs (Da[r][l]) >fabs (Da[i][l])) r=i;        if (Fabs (Da[r][l]) <eps) {h--;continue;}        if (r!=h) F (i,l,n+1) swap (da[r][i],da[h][i]);            F (I,h+1,n) if (Fabs (Da[i][l]) >eps) {double t=da[i][l]/da[h][l];            F (j,l,n+1) da[i][j]-=da[h][j]*t;        da[i][l]=0; }} F (I,h,n) if (Fabs (Da[i][n+1]) &Gt;eps) return-1;//no solution if (h<n+1) return n+1-h;//free element number C (i,1,n) {double tmp=da[i][n+1];        F (J,i+1,n) tmp-=ans[j]*da[i][j];    Ans[i]= (Tmp/da[i][i]); } return 0;}    int main () {n=rd ();    F (i,1,n) scanf ("%lf", &a[i]);          F (i,1,n) F (j,1,n) {double T; scanf ("%lf", &t);        da[i][j]=2* (T-a[j]);    DA[I][N+1]+=T*T-A[J]*A[J];    } gauss ();    F (i,1,n-1) printf ("%.3lf", Ans[i]);    printf ("%.3lf\n", Ans[n]); return 0;}

[luogu4035 JSOI2008] spherical space Generator (matrix 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.