"Gaussian elimination element" bzoj1013 [JSOI2008] spherical space generator sphere

Source: Internet
Author: User

Seek the god of ~>_< to forgive

Based on the relationship of equal radii, the n+1 two-time equations are established.

Then each and the previous subtract two entries, get n a linear equation.

#include <cstdio> #include <cmath> #include <algorithm> #include <cstring>using namespace std;# Define N 11int n;double b[n][n+1],a[n][n+1],x[n],b[n],pl[n+1][n];d ouble sqr (double x) {return x*x;} void Guass_jordan () {memcpy (b,a,sizeof (A)), for (int i=1;i<=n;++i) b[i][n+1]=b[i];for (int i=1;i<=n;++i)//enumeration:  The first unknown is being eliminated, and then the I equation is discarded, matrix row, column-1 {int pivot=i;  for (int j=i+1;j<=n;++j)//Enumeration J: The equation of the highest absolute value of the coefficients of the unknown being processed is swapped to the line I if (Fabs (B[j][i]) >fabs (b[pivot][i)) pivot=j;  Swap (B[i],b[pivot]);  if (Fabs (B[i][i]) <eps)//If all (maximum) of the unknown coefficient is 0, indicating less an unknown number, there is an infinity solution for (int j=i+1;j<=n+1;++j) b[i][j]/=b[i][i];        for (int j=1;j<=n;++j) if (i!=j)//Enumerates all equations, removes the first unknown for (int k=i+1;k<=n+1;++k) from the first J equation, and subtracts the number of the first k unknowns in the J  B[J][K]-=B[J][I]*B[I][K]; }for (int i=1;i<=n;++i) x[i]=b[i][n+1];}  int main () {scanf ("%d", &n), for (int. i=1;i<=n+1;++i) {for (int j=1;j<=n;++j) scanf ("%lf", &pl[i][j]); if (i>1) for (int j=1;j<=n;++j) {B[I-1]+=SQR (pl[i-1][J])-sqr (Pl[i][j]);    A[I-1][J]=2.0*PL[I-1][J]-2.0*PL[I][J]; }}guass_jordan (); for (int i=1;i<n;++i) printf ("%.3f", X[i]);p rintf ("%.3f\n", X[n]); return 0;}

Gaussian elimination bzoj1013 [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.