ZOJ 3645 BiliBili

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.

Railgun_Kuroko.jpg

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 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.

Sample Input

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

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个一次方程,然后通过高斯消元得出结论

但是重点在于高斯消元板子的应用

不同的增广矩阵会得到精度不太相同的解

答案可能出现-0.000000001这样的答案,所以有可能有些人一次就过了,有些人很久都被卡。

//      whn6325689
//		Mr.Phoebe
//		http://blog.csdn.net/u013007900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <numeric>
#pragma comment(linker, "/STACK:1024000000,1024000000")


using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;

#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define MID(x,y) (x+((y-x)>>1))
#define speed std::ios::sync_with_stdio(false);
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LLINF 1LL<<62

template<class T>
inline bool read(T &n)
{
    T x = 0, tmp = 1;
    char c = getchar();
    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
    if(c == EOF) return false;
    if(c == '-') c = getchar(), tmp = -1;
    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
    n = x*tmp;
    return true;
}
template <class T>
inline void write(T n)
{
    if(n < 0)
    {
        putchar('-');
        n = -n;
    }
    int len = 0,data[20];
    while(n)
    {
        data[len++] = n%10;
        n /= 10;
    }
    if(!len) data[len++] = 0;
    while(len--) putchar(data[len]+48);
}
//-----------------------------------

const int N=15; 

using namespace std;

int sgn(double x)
{
    if( x > eps) return 1;
    if( x < -eps) return -1;
    return 0;
}

int Gauss(int n,int m,double a[][N])
{
    int i,j,r,c,pvt;
    double maxp;
    for(r=0,c=0;r<n && c<m;++r,++c)
    {
        for(maxp = 0,i=r;i<n;++i)
            if(fabs(a[i][c]) > fabs(maxp)) maxp = a[pvt=i][c];
        if(sgn(maxp) == 0)
        {
            r--;
            continue;
        }
        if(pvt != r)
            for(j=r;j<=m;++j) swap(a[r][j],a[pvt][j]);
        for(j=c+1;j<=m;++j)
        {
            a[r][j] /= maxp;
            for(i=r+1;i<n;++i)
                a[i][j] -= a[i][c]*a[r][j];
        }
    }

    for(i=r;i<n;++i)
        if(sgn(a[i][m])) return -1;
    if(r < m) return m-r;
    for(i=m-1;i>=0;--i)
        for(j=i+1;j<m;++j)
        a[i][m] -= a[j][m]*a[i][j];
    return 0;
}

int n;
double a[N][N];
double b[N][N];
int t;

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        for(int i=0;i<12;i++)
            for(int j=0;j<12;j++)
            scanf("%lf",&b[i][j]);

        memset(a,0,sizeof(a));

        for(int i=0;i<11;i++)
        {
            a[i][11] = b[i][11]*b[i][11] - b[i+1][11]*b[i+1][11];
            for(int j=0;j<11;j++)
                a[i][11] -= b[i][j]*b[i][j];
            for(int j=0;j<11;j++)
                a[i][11] += b[i+1][j]*b[i+1][j];
        }

        for(int i=0;i<11;i++)
            for(int j=0;j<11;j++)
            a[i][j] = (-2) * (b[i][j] - b[i+1][j]);

        //for(int i=0;i<11;i++)
        //    for(int j=0;j<12;j++)
        //    printf("%.2lf%c",a[i][j],j==11?'\n':' ');

        Gauss(11,11,a);
        for(int i=0;i<11;i++)
        printf("%.2lf%c",a[i][11]+eps,i==10?'\n':' ');
    }
    return 0;
}

顺便扯一句

如果只有11个二次方程怎么算出结果

据说是通过算出几个可能的11维向量,然后取交集

...大概如此



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值