Bzoj 1013 [JSOI2008] spherical space generator sphere

Source: Internet
Author: User

1013: [JSOI2008] spherical space generator sphere time limit:1 Sec Memory limit:162 MB
submit:3074 solved:1614
[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

Exercises

We set the sphere to X (x1,x2,..., xn)

Suppose there are two points a (a1,a2,..., an) and B (B1,b2,..., bn)

Then we can get two equations.

(X1-A1) ^2+ (X2-A2) ^2+...+ (Xn-an) ^2=r^2

(X1-B1) ^2+ (X2-B2) ^2+...+ (xn-bn) ^2=r^2

These equations are all two times and cannot be applied to Gaussian elimination

But we can do some processing. Subtract the above two equations to get a

(A1-B1) x1+ (A2-B2) x2+...+ (an-bn) xn=[(a1^2-b1^2) + (a2^2-b2^2) +...+ (an^2-bn^2)]/2

R is eliminated, n equations, n unknowns can be applied to Gaussian elimination template

The template sleeve is Huang long ...

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;TenInlineintRead () { One     intx=0, sig=1;CharCh=GetChar (); A      while(!isdigit (CH)) {if(ch=='-') sig=-1; ch=GetChar ();} -      while(IsDigit (CH)) x=Ten*x+ch-'0', ch=GetChar (); -     returnx*=Sig; the } -InlinevoidWriteintx) { -     if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; -     intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; +      for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } + using namespacestd; A Const intmaxn= -+5;Const Doubleeps=1e-7; at intNDoubleF[MAXN],A[MAXN][MAXN]; - DoubleSqrDoublex) {returnx*x;} - voidIni () { -n=read (); -      for(intI=1; i<=n;i++) scanf ("%LF",&f[i]); -      for(intI=1; i<=n;i++) in          for(intj=1; j<=n;j++){ -             DoubleT; toscanf"%LF",&t); +a[i][j]=2* (tf[j]); -a[i][n+1]+=SQR (t)-Sqr (F[j]); the         } * } $ BOOLGauss () {Panax Notoginseng     intnow=1, to; -      for(intI=1; i<=n;i++){ the          for(to=now;to<=n;to++)if(Fabs (A[to][i]) >eps) Break;if(to>n)Continue; +         if(To!=now) for(intj=1; j<=n+1; j + +) Swap (a[to][j],a[now][j]); A         Doublet=A[now][i]; the          for(intj=1; j<=n+1; j + +) a[now][j]/=T; +          for(intj=1; j<=n;j++)if(j!=Now ) { -T=a[j][i]; for(intk=1; k<=n+1; k++) a[j][k]-=t*A[now][k]; $}now++; $     } -      for(inti=now;i<=n;i++)if(Fabs (a[i][n+1]) >eps)return false; -     return true; the } - voidinit () {Wuyi ini (); the     return; - } Wu voidWork () { - Gauss (); About     return; $ } - voidprint () { -      for(intI=1; i<n;i++) printf ("%.3LF", a[i][n+1]); -printf"%.3LF", a[n][n+1]); A     return; + } the intMain () { -Init (); work ();p rint ();return 0; $}

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