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
//浙大月赛的一道题。列出方程后发现是12个2次方程,那么用后面的11个都减去第一个便可以化简为1次方程组,边可以直接利用高斯消元求解了。
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<queue> #include<stack> #include<map> #include<vector> #include<algorithm> #include<ctime> using namespace std; double num[15][15]; double a[15][15],x[15]; bool free_x[15]; double free_num; int gcd(int a, int b) { if(b==0) return a; return gcd(b,a%b); } int lcm(int a, int b) { return a*b/gcd(a,b); } void Gauss(int n) { int equ=n,var=n; int i,j,k,max_r,col; double ta,tb; double LCM,temp; int free_x_num; int free_index; col=0; for(k=0;k<equ&&col<var;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(max_r!=k) for(j=k;j<var+1;j++) swap(a[k][j],a[max_r][j]); if(a[k][col]==0) { k--; continue; } for(i=k+1;i<n; i++) if(a[i][col]!=0) { tb=a[i][col]/a[k][col]; for(j=col;j<=n;j++) a[i][j]=a[i][j]-a[k][j]*tb; } } double tmp; if(k<n) { for(i=k-1;i>=0;i--) { free_x_num = 0; for(j=0;j<n;j++) if(a[i][j]!=0&&free_x[j]) free_x_num++,free_index=j; if(free_x_num>1) continue; tmp = a[i][n]; for(j=0;j<n;j++) if(a[i][j]!=0&&j!=free_index) tmp-=a[i][j]*x[j]; x[free_index]=tmp; free_x[free_index]=0; } // return n-k; } for(i=n-1;i>=0;i--) { tmp=a[i][n]; for(j=i+1;j<n;j++) if(a[i][j]!=0) tmp-=a[i][j]*x[j]; x[i] =tmp/a[i][i]; } for(i=0;i<10;i++) printf("%.2lf ",x[i]); printf("%.2lf\n",x[i]); return ; } int main() { int T,i,j,k,n; scanf("%d",&T); while(T--) { memset(a,0.0,sizeof(a)); memset(x,0.0,sizeof(x)); for(i=0;i<12;i++) for(j=0;j<12;j++) scanf("%lf",&num[i][j]); for(i=1;i<12;i++) //建立新的高斯消元组 { a[i-1][11]=num[i][11]*num[i][11]-num[i-1][11]*num[i-1][11]; for(j=0;j<11;j++) { a[i-1][j]=2.0*num[i-1][j]-2.0*num[i][j]; a[i-1][11]-=(num[i][j]*num[i][j]-num[i-1][j]*num[i-1][j]); } } Gauss(11); } return 0; }