Shirai Kuroko is a Senior One student. Almost everyone in Academy City have super powers, and Kuroko is good at using it. Her ability is "Teleporting", which can make people to transfer in the eleven dimension, and it shows like moving instantly in general people's eyes.
In fact, the theory of the ability is simple. Each time, Kuroko will calculate the distance between some known objects and the destination in the eleven dimension so that Kuroko can get the coordinate of the destination where she want to go and use her ability.
Now we have known that the coordinate of twelve objects in the eleven dimension Vi = (Xi1,Xi2, ... ,Xi11), and 1 <= i <= 12. We also known that the distance Di between the destination and the object. Please write a program to calculate the coordinate of the destination. We can assume that the answer is unique and any four of the twelve objects are not on the same planar.
The first line contains an integer T, means there are T test cases. For each test case, there are twelve lines, each line contains twelve real numbers, which means Xi1,Xi2, ... ,Xi11 and Di. T is less than 100.
For each test case, you need to output eleven real numbers, which shows the coordinate of the destination. Round to 2 decimal places.
1 1.0 0 0 0 0 0 0 0 0 0 0 7.0 0 1.0 0 0 0 0 0 0 0 0 0 7.0 0 0 1.0 0 0 0 0 0 0 0 0 7.0 0 0 0 1.0 0 0 0 0 0 0 0 7.0 0 0 0 0 1.0 0 0 0 0 0 0 7.0 0 0 0 0 0 1.0 0 0 0 0 0 7.0 0 0 0 0 0 0 1.0 0 0 0 0 7.0 0 0 0 0 0 0 0 1.0 0 0 0 7.0 0 0 0 0 0 0 0 0 1.0 0 0 7.0 0 0 0 0 0 0 0 0 0 1.0 0 7.0 0 0 0 0 0 0 0 0 0 0 1.0 7.0 7.0 0 0 0 0 0 0 0 0 0 0 11.0
-2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00
#include<iostream> #include<cstdlib> #include<stdio.h> #include<memory.h> #include<math.h> using namespace std; const double eps = 1e-12; double a[12][12]; const int n=11; double xx[12][12],x[12]; bool free_x[12]; int sgn(double x){ return (x>eps)-(x<-eps); } int gauss() { int i, j, k; int max_r; int col; double temp; int free_x_num; int free_index; int equ = n,var = n; col = 0; memset(free_x,true,sizeof(free_x)); for (k = 0; k < equ && col < var; k++, col++) { max_r = k; for (i = k + 1; i < equ; i++) { if (sgn(fabs(a[i][col]) - fabs(a[max_r][col]))>0) max_r = i; } if (max_r != k) { for (j = k; j < var + 1; j++) swap(a[k][j], a[max_r][j]); } if (sgn(a[k][col]) == 0 ) { k--; continue; } for (i = k + 1; i < equ; i++) { if (sgn(a[i][col])!=0) { double t = a[i][col] / a[k][col]; for (j = col; j < var + 1; j++) { a[i][j] = a[i][j] - a[k][j] * t; } } } } if (k < var) { for (i = k - 1; i >= 0; i--) { free_x_num = 0; for (j = 0; j < var; j++) { if ( sgn(a[i][j])!=0 && free_x[j]){ free_x_num++, free_index = j; } } if(free_x_num>1) continue; temp = a[i][var]; for (j = 0; j < var; j++) { if (sgn(a[i][j])!=0 && j != free_index) temp -= a[i][j] * x[j]; } x[free_index] = temp / a[i][free_index]; free_x[free_index] = 0; } return var - k; } for (i = var - 1; i >= 0; i--) { temp = a[i][var]; for (j = i + 1; j < var; j++) { if (sgn(a[i][j])!=0) temp -= a[i][j] * x[j]; } x[i] = temp / a[i][i]; } return 0; } int main() { int t; scanf("%d",&t); while(t--) { memset(a,0,sizeof(a)); memset(x,0,sizeof(x)); for(int i=0;i<12;i++) for(int j=0;j<12;j++) scanf("%lf",&xx[i][j]); double sum=0; for(int i=0;i<11;i++) sum+=xx[11][i]*xx[11][i]; for(int i=0;i<11;i++) { for(int j=0;j<11;j++) { a[i][j]=2*(xx[i][j]-xx[11][j]); a[i][11]+=xx[i][j]*xx[i][j]; } a[i][11]+=-xx[i][11]*xx[i][11]+xx[11][11]*xx[11][11]-sum; } gauss(); printf("%.2lf",x[0]); for(int i=1;i<11;i++) printf(" %.2lf",x[i]); cout<<endl; } }