zoukankan      html  css  js  c++  java
  • BZOJ 1013 球形空间产生器

    Description

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

    Input

    第一行是一个整数,n。接下来的n+1行,每行有n个实数,表示球面上一点的n维坐标。每一个实数精确到小数点后6位,且其绝对值都不超过20000。

    Output

    有且只有一行,依次给出球心的n维坐标(n个实数),两个实数之间用一个空格隔开。每个实数精确到小数点后3位。数据保证有解。你的答案必须和标准输出一模一样才能够得分。

    Sample Input

    2
    0.0 0.0
    -1.0 1.0
    1.0 0.0

    Sample Output

    0.500 1.500

    HINT

    数据规模:

    对于40%的数据,1<=n<=3

    对于100%的数据,1<=n<=10

    提示:给出两个定义:

    1、 球心:到球面上任意一点距离都相等的点。

    2、 距离:设两个n为空间上的点A, B的坐标为(a1, a2, …, an), (b1, b2, …, bn),则AB的距离定义为:dist = sqrt( (a1-b1)^2 + (a2-b2)^2 + … + (an-bn)^2 )

    Source

     高斯消元的裸题吧。两个相邻的方程一减,线性方程就出来了。

    #include<iostream>
    #include<cmath>
    #include<cstring>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    
    #define esp (1e-8)
    #define maxn 15
    double s[maxn][maxn],a[maxn][maxn],ans[maxn]; int n;
    
    inline double qua(double x) {return x*x;}
    
    inline void gauss()
    {
        int i,j,k;
        for (i = 1;i <= n;++i)
        {
            for (j = i;fabs(s[j][i])<=esp;++j);
            for (k = i;k <=n+1;++k)
                swap(s[j][k],s[i][k]);
            for (j = i+1;j <= n;++j)
                if (fabs(s[j][i]) > esp)
                {
                    double p = s[i][i]/s[j][i];
                    for (k = i;k <= n+1;++k)
                        s[j][k] = s[i][k]-s[j][k]*p; 
                }
        }
        for (i = n;i;--i)
        {
            for (j = i + 1;j <= n;++j)
                s[i][n+1] -= ans[j]*s[i][j];
            ans[i] = s[i][n+1]/s[i][i];
        }
    }
    
    int main()
    {
        freopen("1013.in","r",stdin);
        freopen("1013.out","w",stdout);
        scanf("%d",&n); int i,j;
        for (i = 0;i <= n;++i) for (j = 1;j <= n;++j) scanf("%lf",a[i]+j);
        for (i = 1;i <= n;++i)
        {
            for (j = 1;j <= n;++j) s[i][j] = 2*(a[i][j]-a[i-1][j]);
            for (j = 1;j <= n;++j) s[i][n+1] += qua(a[i][j]);
            for (j = 1;j <= n;++j) s[i][n+1] -= qua(a[i-1][j]);
        }
        gauss();
        for (i = 1;i < n;++i) printf("%.3lf ",ans[i]);
        printf("%.3lf",ans[n]);
        fclose(stdin); fclose(stdout);
        return 0;
    }
  • 相关阅读:
    Jmeter之Bean shell使用(一)
    CSS知识点 2
    0523 CSS知识点
    0522 HTML表单 CSS基础
    0521 HTML基础
    0515线程
    0514 队列 管道 进程池 回调函数
    0510进程 multiprocess模块
    0509操作系统发展史 进程
    0507黏包
  • 原文地址:https://www.cnblogs.com/mmlz/p/4226149.html
Copyright © 2011-2022 走看看