zoukankan      html  css  js  c++  java
  • bzoj1013

    这道题对大佬来说都不屑写,但鉴于我是蒟蒻,不会高斯消元啊啊啊啊啊啊啊。

    献上大佬的教程一篇:http://www.cnblogs.com/Robert-Yuan/p/4621481.html

    设球心坐标为(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

    ....

    只要拿后n个方程分别去减第一个方程,就可以得到n个一次方程了

    2*(a1-b1)x1+2*(a2-b2)*x2+.....+2*(an-bn)xn=a1^2-b1^2+a2^2-b2^2....an^2-bn^2

    ---thy_asdf

    #include <stdio.h>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <queue>
    #include <vector>
    using namespace std;
    const double eps=1e-6;
    double f[21],a[21][21];
    int n;
    double sqr(double x){return x*x;}
    void gauss()
    {
      int now=1,v;double t;
      for(int i=1;i<=n;i++)
      {
          for(v=now;v<=n;v++)if(abs(a[v][i])>eps)break;
          if(v>n)continue;
          if(v!=now)
           for(int j=1;j<=n+1;j++)
            swap(a[v][j],a[now][j]);
          t=a[now][i];
          for(int j=1;j<=n+1;j++)a[now][j]/=t;
          for(int j=1;j<=n;j++)
           if(j!=now)
           {
             t=a[j][i];
             for(int k=1;k<=n+1;k++)
              a[j][k]-=t*a[now][k];
           }
           now++;
      }
      return;
    }
    int main()
    {
      scanf("%d",&n);
      for(register int i=1;i<=n;i++)scanf("%lf",&f[i]);
      for(register int i=1;i<=n;i++)
       for(register int j=1;j<=n;j++)
       {
            double t;
            scanf("%lf",&t);
            a[i][j]=2*(t-f[j]);
            a[i][n+1]+=sqr(t)-sqr(f[j]);
       }
       gauss();
       for(int i=1;i<=n-1;i++)
        printf("%.3lf ",a[i][n+1]);
       printf("%.3lf
    ",a[n][n+1]);
       return 0;
    }
    View Code
  • 相关阅读:
    Leetcode_02【两数相加】——【难度:中】
    Leetcode_39【组合总和】
    Leetcode_38【报数】
    Leetcode_36【有效的数独】
    Leetcode_35【搜索插入位置】
    51nod1347 旋转字符串
    WebH
    ExcelHelper
    文件二进制与String相互转换
    汇编语言里 eax, ebx, ecx, edx, esi, edi, ebp, esp
  • 原文地址:https://www.cnblogs.com/new-hand/p/7724006.html
Copyright © 2011-2022 走看看