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.

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 means Xi1,Xi2, ... ,Xi11and DiT 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.

题目大意:11维度上有一个未知的点,现在已知12个点的坐标和他们到这个未知的点的距离,求这个未知的点的坐标。

思路:设未知的点为(p1, p2, ……, pn)

那么对于每个已知点,列方程(xi1 - p1)^2 + (xi2 - p2)^2 + …… + (xin - pn)^2 = Di^2

然后,对于前11个方程,减去第12个方程,就能得到一个线性方程组。

然后高斯消元解即可。

PS:我的代码不加那个EPS会跪,我觉得以后没事还是把它加上吧……

代码(0MS):

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std; const double EPS = 1e-;
const int MAXN = ; double mat[MAXN][MAXN];
int n = , T; inline int sgn(double x) {
return (x > EPS) - (x < -EPS);
} void guess_eliminatioin() {
for(int i = ; i < n; ++i) {
int r = i;
for(int j = i + ; j < n; ++j)
if(fabs(mat[j][i]) > fabs(mat[r][i])) r = j;
if(sgn(mat[r][i]) == ) continue;
if(r != i) for(int j = ; j <= n; ++j) swap(mat[r][j], mat[i][j]);
for(int j = n; j >= i; --j)
for(int k = i + ; k < n; ++k) mat[k][j] -= mat[k][i] / mat[i][i] * mat[i][j];
}
for(int i = n - ; i >= ; --i) {
for(int j = i + ; j < n; ++j)
mat[i][n] -= mat[j][n] * mat[i][j];
mat[i][n] /= mat[i][i];
}
} int main() {
scanf("%d", &T);
while(T--) {
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) scanf("%lf", &mat[i][j]);
for(int i = ; i < n; ++i) {
mat[i][n] = mat[i][n] * mat[i][n] - mat[n][n] * mat[n][n];
for(int j = ; j < n; ++j) {
mat[i][n] -= mat[i][j] * mat[i][j] - mat[n][j] * mat[n][j];
mat[i][j] = - * mat[i][j] + * mat[n][j];
}
}
guess_eliminatioin();
for(int i = ; i < n - ; ++i) printf("%.2f ", mat[i][n] + EPS);
printf("%.2f\n", mat[n - ][n] + EPS);
}
}

ZOJ 3645 BiliBili(高斯消元)的更多相关文章

  1. ZOJ 3645 BiliBili 高斯消元 难度:1

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4835 由题意,有: (x1-x11)^2 + (x2-x12)^2 ... = ...

  2. 「ZOJ 1354」Extended Lights Out「高斯消元」

    题意:给定一个\(5\times 6\)的棋盘的\(01\)状态,每次操作可以使它自己和周围四个格子状态取反,求如何操作,输出一个\(01\)矩阵 题解:这题可以通过枚举第一行的状态然后剩下递推来做, ...

  3. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  4. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  5. *POJ 1222 高斯消元

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9612   Accepted: 62 ...

  6. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  7. hihoCoder 1196 高斯消元·二

    Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...

  8. BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基

    [题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...

  9. SPOJ HIGH Highways ——Matrix-Tree定理 高斯消元

    [题目分析] Matrix-Tree定理+高斯消元 求矩阵行列式的值,就可以得到生成树的个数. 至于证明,可以去看Vflea King(炸树狂魔)的博客 [代码] #include <cmath ...

随机推荐

  1. JDK核心包学习

    StringBuffer   线程安全.可变字符序列 StringBuilder   非线程安全.可变字符序列,比StringBuffer更快 Boolean 使用valueOf产生Boolean实例 ...

  2. 关于hive的存储格式

    1.存储格式 textfile rcfile orc parquet 2.存储方式 按行存储 ->textfile 按列存储 ->parquet 3.压缩比 4.存储textfile的原文 ...

  3. php--validate表单验证

    validate表单验证扩展规则 添加自定义检验(验证class) 获取html加入 class <input id="D_NUMBER" name="D_NUMB ...

  4. 【Android学习5】Clean 之后R文件丢失

    今天一不小心Clean下,发现R文件的资源都不可用,查阅资料发现是自己不小将一个.xml文件的文件名中包含了一个大写字母(为何不能包含大写呢?)   参考解决方法如下: 首先确定你的SDK是新的. 其 ...

  5. Asp.net MVC4 网站发布

    1.打开你的VS2012网站项目,右键点击项目-->发布: 2.弹出网站发布设置面板,点击<新建..>创建新的发布配置文件: 3.输入配置文件名称:(名称随便) 3.在发布方法中选“ ...

  6. imx6 MFG TOOL 分析

    之前分析过mfgtool的内容,最近从官网下载,返现新版的mfgtool工具将imx6各种版本的linux/android都使用一个工具进行烧录.所以从新分析一下. 新版与旧版的一个区别是烧写使用的u ...

  7. 为什么玩VR眼镜会头晕?

    为什么玩VR眼镜会头晕?看完本文你就懂了   很多用户都体验过各式各样的VR眼镜或者说头盔,但是不管哪一款,都很容易出现头晕的情况.相信大家都纳闷过,为什么玩VR眼镜会头晕?实际上这是和设备本身的技术 ...

  8. 呛口大话APP 移动端到底怎么玩

    [上海站]活动概况 时间:2016年04月09日13:30-16:30 地点:上海市黄浦区黄陂北路227号中区广场105室WE+联合办公空间 主办:APICloud.七牛.听云 报名网址:http:/ ...

  9. mysql 恢复

    一.备份的目的 做灾难恢复:对损坏的数据进行恢复和还原需求改变:因需求改变而需要把数据还原到改变以前测试:测试新功能是否可用 二.备份需要考虑的问题 可以容忍丢失多长时间的数据:恢复数据要在多长时间内 ...

  10. [PCL]NDT点云匹配方法

    测试NDT方法的Demo,http://pointclouds.org/documentation/tutorials/normal_distributions_transform.php#norma ...