BiliBili zoj 3645 (高斯消元,数学)
来源:互联网 发布:relief算法 matlab 编辑:程序博客网 时间:2024/04/30 00:42
Description
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, ... ,Xi11 and Di. 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个线性方程,然后做一次高斯即可得到答案,需要注意的是,做guass的时候,由于有负数项存在,交换两行时,应该选择绝对值较高的那个,同时应该避免输出-0.00,因为这两点wa了好几次。
代码:
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const long M=20;double a[M][M];void guass(long n){for (long i=0;i<n;++i){long r=i;for (long j=i+1;j<n;++j) if (fabs(a[j][i])>fabs(a[r][i])) r=j;for (long j=i;j<=n;++j) swap(a[i][j],a[r][j]);for (long k=i+1;k<n;++k){double rate=a[k][i]/a[i][i];for (long j=i;j<=n;++j) a[k][j]-=rate*a[i][j];}}for (long i=n-1;i>=0;--i){for (long j=i+1;j<n;++j)a[i][n]-=a[j][n]*a[i][j];a[i][n]/=a[i][i];}}double fix(double x){if (fabs(x)<1e-8) return 0;return x;}double mat[M][M],b[M];long t;int main(){scanf("%d",&t);while (t--){for (long i=0;i<12;++i){double res=0.0;for (long j=0;j<11;++j){scanf("%lf",&mat[i][j]);res+=mat[i][j]*mat[i][j];mat[i][j]*=(-2);}scanf("%lf",&b[i]);b[i]=b[i]*b[i]-res;}for (long i=0;i<11;++i){for (long j=0;j<11;++j)a[i][j]=mat[i][j]-mat[i+1][j];a[i][11]=b[i]-b[i+1];}guass(11);for (long i=0;i<11;++i){printf("%.2f",fix(a[i][11]));if (i<10) printf(" ");else printf("\n");}}return 0;}
- BiliBili zoj 3645 (高斯消元,数学)
- ZOJ 3645 BiliBili (高斯消元)
- ZOJ-3645 BiliBili(高斯消元)
- ZOJ 3645 :BiliBili _高斯消元
- zoj - 3645 - BiliBili(线性方程组)
- ZOJ 3645 BiliBili
- ZOJ 3645 BiliBili
- ZOJ月赛 悲剧的BiliBili 高斯消元
- zoj 2952 (数学)
- zoj 2060(数学水。。。)
- zoj 3710 Friends(数学)
- ZOJ 2680 Clock(数学)
- ZOJ-3791(组合数学)
- ZOJ 2975 数学(K)
- ZOJ 3919 Ellipse(数学)
- ZOJ 3903 Ant (数学)
- ZOJ 3224(数学+暴力)
- zoj 3329(dp-数学期望)
- 协议和委托 之 开车
- CHtmlView iFrame 绘制
- uva 147 - Dollars(动态规划--完全背包)
- MySQL十大优化技巧
- mysql HA方案: MHA
- BiliBili zoj 3645 (高斯消元,数学)
- hadoop的mapreduce作业中经常出现Java heap space解决方案
- VIm配置与一般管理命令
- Linux管理员不可不知的五大使用命令
- Oracle 11g RAC 环境下单实例非缺省监听及端口配置
- According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- MFC自制贪吃蛇游戏设计心得
- poj 2480 Longge's problem(欧拉函数的性质)
- android学习笔记1-activity回调,重写onActivityResult