Bzoj 1013: [JSOI2008] spherical space generator sphere Gaussian elimination element

Source: Internet
Author: User


Subtract the upper and lower two equations and then Gaussian elimination

1013: [JSOI2008] spherical space generator sphere time limit: 1 Sec Memory Limit: 162 MB
Submit: 2901 Solved: 1517
[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

[Submit] [Status] [Discuss]


/* ***********************************************author:ckbosscreated time:2015 May 15 Friday 07:45 04 seconds file Name : bzoj1013.cpp************************************************ * * #include <iostream> #include <cstdio># Include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib > #include <vector> #include <queue> #include <set> #include <map>using namespace Std;const Double eps=1e-8;const int maxn=40;double a[maxn][maxn],x[maxn];int equ,val;bool Gauss () {int i,j,k,col,max_r;for (k=0, col=0;k<equ&&col<val;k++,col++) {max_r=k;for (i=k+1;i<equ;i++) if (Fabs (A[i][col]) >fabs (a[max_ R][col]) max_r=i;if (Fabs (A[max_r][col]) <eps) return False;if (K!=max_r) {for (int j=col;j<val;j++) swap (A[k][j] , A[max_r][j]); swap (X[k],x[max_r]);} X[k]/=a[k][col];for (j=col+1;j<val;j++) a[k][j]/=a[k][col];a[k][col]=1;for (i=0;i<equ;i++) {if (i!=k) {x[i]-=x [K]*a[i][k];for (j=col+1;j<val;j++) a[i][j]-=a[k][J]*a[i][col];a[i][col]=0;}}} return true;} int n;double Cs[maxn][maxn];int Main () {//freopen ("In.txt", "R", stdin),//freopen ("OUT.txt", "w", stdout), scanf ("%d", &n); for (int i=0;i<n+1;i++) for (int j=0;j<n;j++) scanf ("%lf", &cs[i][j]);//build matrixequ=n; val=n;for (int i=0;i<n;i++) {int ii=i+1;double sum=0;for (int j=0;j<n;j++) {a[i][j]=2* (cs[ii][j]-cs[i][j]); sum+= (Cs[ii][j]-cs[i][j]) * (Cs[ii][j]+cs[i][j]);} X[i]=sum;} Gauss (); for (int i=0;i<val;i++) {printf ("%.3lf%c", X[i], (i==val-1)? '        \ n ': ');} return 0;}


Bzoj 1013: [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.