zoj 3645(高斯—浮点型——模板)
来源:互联网 发布:移动4g网络覆盖范围 编辑:程序博客网 时间:2024/05/21 07:08
Shirai Kuroko is a Senior One student. Almost everyone in Academy City have super powers, andKuroko 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 thatKuroko 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 dimensionVi = (Xi1,Xi2, ... ,Xi11), and 1 <=i <= 12. We also known that the distanceDi 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.
Input
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 meansXi1,Xi2, ... ,Xi11 andDi. T is less than 100.
Output
For each test case, you need to output eleven real numbers, which shows the coordinate of the destination. Round to 2 decimal places.
Sample Input
11.0 0 0 0 0 0 0 0 0 0 0 7.00 1.0 0 0 0 0 0 0 0 0 0 7.00 0 1.0 0 0 0 0 0 0 0 0 7.00 0 0 1.0 0 0 0 0 0 0 0 7.00 0 0 0 1.0 0 0 0 0 0 0 7.00 0 0 0 0 1.0 0 0 0 0 0 7.00 0 0 0 0 0 1.0 0 0 0 0 7.00 0 0 0 0 0 0 1.0 0 0 0 7.00 0 0 0 0 0 0 0 1.0 0 0 7.00 0 0 0 0 0 0 0 0 1.0 0 7.00 0 0 0 0 0 0 0 0 0 1.0 7.07.0 0 0 0 0 0 0 0 0 0 0 11.0
Sample Output
-2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00 -2.00
思路:12个方程,11个未知数,用最后一个方程和前11个方程相减,消掉X^2,11个方程,11个未知数,可以解。。。。浮点型高斯,可以当模版用喽!!!
#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 data[12][12],x[12];bool free_x[12];int sgn(double x){ return (x>eps)-(x<-eps);}int gauss(){ double temp; int i,j,k,max_r,col=0,equ=n,var=n; int free_x_num,free_index; 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[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--) { double 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,i,j,sum; scanf("%d",&t); while(t--) { memset(x,0,sizeof(x)); memset(a,0,sizeof(a)); for(i=0;i<12;i++) for(j=0;j<12;j++) scanf("%lf",&data[i][j]); sum=0; for(i=0;i<11;i++) sum+=data[11][i]*data[11][i]; for(i=0;i<11;i++) { for(j=0;j<11;j++) { a[i][j]=2*(data[i][j]-data[11][j]); a[i][11]+=data[i][j]*data[i][j]; } a[i][11]+=data[11][11]*data[11][11]-data[i][11]*data[i][11]-sum; } gauss(); printf("%.2lf",x[0]); for(i=1;i<11;i++) printf(" %.2lf",x[i]); printf("\n"); } return 0;}
- zoj 3645(高斯—浮点型——模板)
- 高斯消元模板——浮点参数型
- BC高精确度函数库—浮点数运算
- 《数字图像处理》——高斯模板的产生
- 圆整错误——有关浮点型
- 避开浮点数——伪浮点数
- 转载:图像高斯平滑滤波分析——如何求高斯滤波模板
- 计算高斯模板
- 计算高斯模板
- ZOJ——5013
- zoj july— 小记
- ZOJ—2610
- 2012浙大九月月赛 zoj3645 BiliBili-----高斯 浮点型
- Java基本数据类型——浮点数型
- PHP学习笔记——整型和浮点型;
- C—learning (字符,转义字符,浮点型,printf函数,
- 高斯过滤得到高斯模板
- 浮点数高斯消元的模板
- Eclipse JD-Eclipse插件
- 透过思科Packet Tracer揭开DSL技术的神秘面纱
- What is the difference between a definition and a declaration?
- 查看main函数的返回值
- Java中的内部类和匿名类
- zoj 3645(高斯—浮点型——模板)
- jqploat 手把手
- open source the 3d android game
- C++: wxWidgets (2) CodeLite 开源C/C++IDE
- QuarkXPress.v9.3.Multilingual.Incl.Keymaker-AGAiN
- 付费搜索广告分析
- peewee 一个轻量级的ORM (四)
- 有关scrollViewDidEndDecelerating的一个小问题
- 网站分析基础概念之会话引用与访问者引用