• JSOI2008球形空间产生器


    P2182 - 【JSOI2008】球形空间产生器

    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

    耒阳大世界(衡阳八中) OJ 1013
    解方程组

    高斯消元裸体,通过一个坐标,可以和其他n个坐标建立起一个n个方程关系,在运用高斯约旦消元法即可;

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<iomanip>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<cstdio>
     7 #include<queue>
     8 #include<ctime>
     9 #include<cmath>
    10 #include<stack>
    11 #include<map>
    12 #include<set>
    13 #define rep(i,a,b) for(register int i=a;i<=b;i++)
    14 #define il inline
    15 #define ll long long
    16 #define db double
    17 using namespace std;
    18 #define eps 0.0000001
    19 const int N=20;
    20 db a[N][N],f[N];
    21 int n;
    22 il int gi();
    23 void Input() {
    24   n=gi();
    25   rep(i,1,n) scanf("%lf",&f[i]);
    26   db t;
    27   rep(i,1,n)
    28     rep(j,1,n) {
    29     scanf("%lf",&t);
    30     a[i][j]=2*(t-f[j]);
    31     a[i][n+1]+=t*t-f[j]*f[j];
    32   }
    33 }
    34 void Gauss() {
    35   rep(i,1,n) {
    36     int line=i;
    37     while(line<=n&&fabs(a[line][i])<=eps) line++;// find 主元
    38     if(line>n) continue;
    39     if(line!=i)  rep(j,1,n+1) swap(a[line][j],a[i][j]) ;
    40     db k=a[i][i];
    41     rep(j,1,n+1)
    42       a[i][j]/=k;// 系数化为1
    43     rep(j,1,n)//bug 1 : j hangshu  X <=n+1 X
    44       if(j!=i) {// bug 2:  a[j][i]<eps ? gun!
    45     k=a[j][i];
    46     rep(o,1,n+1) a[j][o]-=k*a[i][o];// Change 0
    47       }
    48    }
    49 }
    50 int main() {
    51     freopen("HNOI.in","r",stdin);
    52     freopen("HNOI.out","w",stdout);
    53     Input();
    54     Gauss();
    55     rep(i,1,n-1) printf("%.3lf ",a[i][n+1]);
    56     printf("%.3lf",a[n][n+1]);
    57     return 0;
    58 }
    59 
    60 il int gi() {
    61     int res=0,f=1;
    62     char ch=getchar();
    63     while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    64     if(ch=='-') ch=getchar(),f=-1;
    65     while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
    66     return res*f;
    67 }
  • 相关阅读:
    Spring/Java error: namespace element 'annotation-config' … on JDK 1.5 and higher
    警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Zhuo' did not find a matching property.
    快速学习Symfony4,Symfony4教程
    window下安装redis报错: creating server tcp listening socket 127.0.0.1:6379: bind No error
    Windows 安装nginx
    js焦点事件:onfocus、onblur、focus()、blur()、select()
    input 输入框只能输入纯数字
    随机抽取不重复的数组元素
    常用 书签 mark 常用网站
    仿真灯泡 电灯泡 灯光 光环闪烁 流星雨
  • 原文地址:https://www.cnblogs.com/ypz999/p/6659334.html
Copyright © 2020-2023  润新知