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

    [[JSOI2008]球形空间产生器](https://www.luogu.org/problemnew/show/P4035)

    高斯消元搞一搞

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    const int maxn = 17;
    
    int n;
    double loc[maxn][maxn];
    double st[maxn],x[maxn];
    void gauss() {
        int t;
        for(int i=1;i<=n;++i) {
            t=i;
            for(int j=i+1;j<=n;++j) if(loc[j][i]>loc[t][i]) t=j;
            if(t!=i) for(int j=i;j<=n+1;++j) std::swap(loc[t][j],loc[i][j]);
            for(int j=i+1;j<=n;++j) {
                double tmp=loc[i][i]/loc[j][i];
                for(int k=i+1;k<=n+1;++k) loc[j][k]=loc[i][k]-tmp*loc[j][k];
            }
        }
        for(int i=n;i>=1;--i) { 
            for(int j=i+1;j<=n;++j) loc[i][n+1]-=x[j]*loc[i][j];
            x[i]=loc[i][n+1]/loc[i][i];
        }
    }
    int main() {
        scanf("%d",&n);
        for(int i=1;i<=n;++i)scanf("%lf",&st[i]);
        for(int i=1;i<=n;++i) 
            for(int j=1;j<=n;++j) {
                double tmp;
                scanf("%lf",&tmp);
                loc[i][j]=2*(st[j]-tmp);
                loc[i][n+1]+=st[j]*st[j]-tmp*tmp;
            }
        gauss();
        for(int i=1;i<=n;++i) printf("%.3lf ",x[i]);
        return 0;
    }
  • 相关阅读:
    推箱子(简易版)
    [LeetCode] Word Ladder II
    [LeetCode] Path Sum
    [LeetCode] Word Ladder
    DFS & BFS
    [LeetCode] Surrounded Regions
    [LeetCode] Add Binary
    [LeetCode] Plus One
    [LeetCode] Single Number II
    [LeetCode] Single Number
  • 原文地址:https://www.cnblogs.com/sssy/p/8594148.html
Copyright © 2011-2022 走看看