zoukankan      html  css  js  c++  java
  • [BZOJ1013][JSOI2008]球形空间产生器sphere

    Description

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

      根据n+1个点的坐标,列出其到球心坐标距离的联等方程,移项就可以得到一个n元一次方程组。

      然后高斯消元就可以了。

      高斯消元在北京的时候有一道类似的题当时就写过,并且调了很久。

      但是那道题没有AC,今天重新写了一遍直接过了。一直都是自己写的模板有时间去参考一些别人的写法。


    program bzoj1013;
    const maxn=15;
    var n,i,j:longint;
        c,r,b:array[-1..maxn]of extended;
        a,l:array[-1..maxn,-1..maxn]of extended;
    
    procedure Gauss(step:longint);
    var i,j,head:longint;
    begin
        if step=1 then
        begin
                    b[n]:=r[1]/l[1,n];
            exit;
        end;
        head:=n-step+1;
        for i:=2 to step do
        begin
            r[i]:=r[i]*l[1,head]/l[i,head];
            for j:=head+1 to n do l[i,j]:=l[i,j]*l[1,head]/l[i,head];
                    l[i,head]:=l[1,head];
        end;
        for i:=1 to step-1 do
        begin
            r[i]:=r[i]-r[i+1];
            for j:=head+1 to n do l[i,j]:=l[i,j]-l[i+1,j];
        end;
        Gauss(step-1);
        for i:=head+1 to n do r[step]:=r[step]-b[i]*l[step,i];
        b[head]:=r[step]/l[step,head];
    end;
    
    begin
        readln(n);
        for i:=1 to n+1 do
        begin
            for j:=1 to n do read(a[i,j]);
            readln;
        end;
        for i:=1 to n+1 do
        begin
            c[i]:=0;
            for j:=1 to n do c[i]:=c[i]+sqr(a[i,j]);
        end;
        for i:=1 to n do
        begin
            r[i]:=(c[i+1]-c[i])/2;
            for j:=1 to n do l[i,j]:=a[i+1,j]-a[i,j];
        end;
        Gauss(n);
        for i:=1 to n-1 do write(b[i]:0:3,' ');writeln(b[n]:0:3);
    end.
        
     
  • 相关阅读:
    [git]使用Idea创建一个git项目
    [git]分支管理策略
    Restful 风格
    [spring boot]idea中实现热部署的方法
    [jquery]JSON.parse()与JSON.stringify()
    [spring mvc]<mvc: annotation-driven />的作用
    [spring mvc][转]<mvc:default-servlet-handler/>的作用
    [mybatis]传值和返回结果
    [spring]@Resource和@Autowired区别对比
    html流程实现
  • 原文地址:https://www.cnblogs.com/mjy0724/p/4409455.html
Copyright © 2011-2022 走看看