zoukankan      html  css  js  c++  java
  • BZOJ 1013: [JSOI2008]球形空间产生器sphere 高斯消元

    1013: [JSOI2008]球形空间产生器sphere

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://www.lydsy.com/JudgeOnline/problem.php?id=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 )

    题意

    题解

    高斯消元

    假设圆心坐标为(x1,x2,x3.....xn)

    那:(a1-x1)^2+(a2-x2)^2.......+(an-xn)^2=r^2

    (b1-x1)^2+(b2-x2)^2.......+(bn-xn)^2=r^2

    两个方程相减得到:(a1-b1)x1+(a2-b2)x2......(an-bn)xn=(a1^2-b1^2)+.......+(an^2-bn^2)/2

    然后高斯消元求解就好了

    代码:

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 1000100
    #define mod 10007
    #define eps 1e-9
    int Num;
    //const int inf=0x7fffffff;   //нчоч╢С
    const int inf=0x3f3f3f3f;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    int n;
    double f[30];
    double a[30][30];
    void gauss()
    {
         int now,to;double t;
         for(int i=1;i<=n;i++)
         {
             now=i;
             for(to=i+1;to<=n;to++)
             if(abs(a[to][i])>abs(a[now][i])) now=to;
             if(now!=i)
             {
                 for(int j=1;j<=n+1;j++)
                 swap(a[i][j],a[now][j]);
             }
             for(int j=i+1;j<=n;j++)
             {
                double tmp=a[j][i]/a[i][i];
                a[j][i]=0;
                for(int k=i+1;k<=n+1;k++)
                a[j][k]-=tmp*a[i][k];
             }
         }
         for(int i=n;i;i--)
         {
             for(int j=n;j>i;j--)
             a[i][n+1]-=a[j][n+1]*a[i][j];
             a[i][n+1]/=a[i][i];
         }
         for(int i=1;i<n;i++)
         printf("%.3lf ",a[i][n+1]);
         printf("%.3lf",a[n][n+1]);
    }
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%lf",&f[i]);
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                double t;
                scanf("%lf",&t);
                a[i][j]=2*(t-f[j]);
                a[i][n+1]+=t*t-f[j]*f[j];
            }
        }
        gauss();
        return 0;
    }
  • 相关阅读:
    linux sort,uniq,cut,wc命令详解
    Linux IO实时监控iostat命令详解
    uniq命令
    四层和七层负载均衡的区别
    keepalived 和 heartbeat对比
    LVS+Keepalived实现负载均衡
    Lvs+heartbeat高可用高性能web站点的搭建
    使用 awk 过滤文本或文件中的字符串
    最全mysql的复制和读写分离
    伤不起
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4749215.html
Copyright © 2011-2022 走看看