受n+1只n维的接触之坐标。给n+1独n维的触及的坐标。给n+1个n维的触发的坐标。

【BZOJ】1013:
[JSOI2008]球形空间发出器sphere

【BZOJ】1013:
[JSOI2008]球形空间有器sphere

【BZOJ】1013: [JSOI2008]球形空间来器sphere,bzojjsoi2008

【BZOJ】1013: [JSOI2008]球形空间来器sphere

题意:给n+1只n维的触及的坐标,要你要出一个暨及时n+1个点距离等的点的坐标;

思路:高斯消元即第i个点和第i+1个点处理发生一个姿势,这样n+1只点恰恰有n个系数的n元变量,即可求解。

式子:Σ( (a[i][j] – x[j])^2 )  = Σ( a[i+1][j] – x[j])^2 )
=>Σ( x[j]*[2*(a[i+1][j]-a[i][j])] ) =
Σ(a[i+1][j]*a[i+1][j] –
a[i][j]*a[i][j]);直接预处理即可;

在意:在Gauss处理发生上三角阵的过程被,每次要选出主对角线绝对值最可怜之行作为参考行,貌似是精度问题。还有即使是归零的历程中,要改成参考行在破除,为了不出新除0的状态。

 

图片 1#include<iostream>
#include<cstdio> #include<cstring>
#include<string.h> #include<algorithm>
#include<map> #include<queue> #include<vector>
#include<cmath> #include<stdlib.h> #include<time.h>
using namespace std; typedef long long ll; #define rep0(i,l,r) for(int
i = (l);i < (r);i++) #define rep1(i,l,r) for(int i = (l);i <=
(r);i++) #define MS0(a) memset(a,0,sizeof(a)) #define MS1(a)
memset(a,-1,sizeof(a)) double a[11][11],A[12][12]; int n; void
Gauss() { int i,j,k; rep1(i,1,n){ int mx = i; rep1(j,i+1,n)
if(fabs(A[mx][i]) < fabs(A[j][i])) mx = j; rep1(j,i,n+1)
swap(A[mx][j],A[i][j]); rep1(j,i+1,n)if(A[i][i] != 0){
double y = A[j][i]/A[i][i]; rep1(k,i,n+1) A[j][k] -=
y*A[i][k]; } } for(int i = n;i >= 1;i–){ rep1(j,i+1,n)
A[i][n+1] -= A[i][j] * A[j][n+1]; A[i][n+1] /=
A[i][i]; //化为系数为1;保证有解,则A[i][i] != 0; } } int main()
{ int i,j; scanf(“%d”,&n); rep1(i,1,n+1) rep1(j,1,n)
scanf(“%lf”,&a[i][j]); rep1(i,1,n) rep1(j,1,n){ A[i][j] =
2*(a[i+1][j] – a[i][j]); A[i][n+1] +=
a[i+1][j]*a[i+1][j] – a[i][j]*a[i][j]; } Gauss();
printf(“%.3f”,A[1][n+1]); rep1(i,2,n) printf(” %.3f”,A[i][n+1]);
} View Code

 

http://www.bkjia.com/Cyy/1098070.htmlwww.bkjia.comtruehttp://www.bkjia.com/Cyy/1098070.htmlTechArticle【BZOJ】1013:
[JSOI2008]球形空间来器sphere,bzojjsoi2008 【BZOJ】1013:
[JSOI2008]球形空间来器sphere
题意:给n+1独n维的触及之坐标,要而请来一个到…

题意:给n+1独n维的触及的坐标,要而请出一个暨这n+1单点距离等的接触之坐标;

题意:给n+1个n维的触发之坐标,要你要来一个至就n+1只点离开等的触及的坐标;

思路:高斯消元即第i个点和第i+1单点处理发生一个姿态,这样n+1独点恰恰有n个系数的n元变量,即可求解。

思路:高斯消元即第i个点和第i+1独点处理发生一个相,这样n+1个点恰恰有n个系数的n元变量,即可求解。

式子:Σ( (a[i][j] – x[j])^2 )  = Σ(
a[i+1][j] – x[j])^2 )

式子:Σ( (a[i][j] – x[j])^2 )  = Σ(
a[i+1][j] – x[j])^2 )

=>   Σ( x[j]*[2*(a[i+1][j]-a[i][j])] ) = Σ(a[i+1][j]*a[i+1][j] – a[i][j]*a[i][j]);直接预处理即可;

=>   Σ( x[j]*[2*(a[i+1][j]-a[i][j])] ) = Σ(a[i+1][j]*a[i+1][j] – a[i][j]*a[i][j]);直接预处理即可;

瞩目:在Gauss处理发生上三角阵的长河被,每次只要选出主对角线绝对值最特别的行作为参考行,貌似是精度问题。还有就是是归零的历程中,要变为参考行再败,为了不出新除0的景象。

瞩目:在Gauss处理发生上三角阵的历程被,每次只要选出主对角线绝对值最充分之行作为参考行,貌似是精度问题。还有即使是归零的进程被,要成参考行再败,为了不出新除0的景。

 

 

图片 2图片 3

图片 4图片 5

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
typedef long long ll;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
double a[11][11],A[12][12];
int n;
void Gauss()
{
    int i,j,k;
    rep1(i,1,n){
        int mx = i;
        rep1(j,i+1,n) if(fabs(A[mx][i]) < fabs(A[j][i])) mx = j;
        rep1(j,i,n+1) swap(A[mx][j],A[i][j]);
        rep1(j,i+1,n)if(A[i][i] != 0){
            double y = A[j][i]/A[i][i];
            rep1(k,i,n+1) A[j][k] -= y*A[i][k];
        }
    }
    for(int i = n;i >= 1;i--){
        rep1(j,i+1,n)   A[i][n+1] -= A[i][j] * A[j][n+1];
        A[i][n+1] /= A[i][i];   //化为系数为1;保证有解,则A[i][i] != 0;
    }
}
int main()
{
    int i,j;
    scanf("%d",&n);
    rep1(i,1,n+1)
        rep1(j,1,n)
            scanf("%lf",&a[i][j]);
    rep1(i,1,n)
        rep1(j,1,n){
            A[i][j] = 2*(a[i+1][j] - a[i][j]);
            A[i][n+1] += a[i+1][j]*a[i+1][j] - a[i][j]*a[i][j];
        }
    Gauss();
    printf("%.3f",A[1][n+1]);
    rep1(i,2,n) printf(" %.3f",A[i][n+1]);
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
typedef long long ll;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
double a[11][11],A[12][12];
int n;
void Gauss()
{
    int i,j,k;
    rep1(i,1,n){
        int mx = i;
        rep1(j,i+1,n) if(fabs(A[mx][i]) < fabs(A[j][i])) mx = j;
        rep1(j,i,n+1) swap(A[mx][j],A[i][j]);
        rep1(j,i+1,n)if(A[i][i] != 0){
            double y = A[j][i]/A[i][i];
            rep1(k,i,n+1) A[j][k] -= y*A[i][k];
        }
    }
    for(int i = n;i >= 1;i--){
        rep1(j,i+1,n)   A[i][n+1] -= A[i][j] * A[j][n+1];
        A[i][n+1] /= A[i][i];   //化为系数为1;保证有解,则A[i][i] != 0;
    }
}
int main()
{
    int i,j;
    scanf("%d",&n);
    rep1(i,1,n+1)
        rep1(j,1,n)
            scanf("%lf",&a[i][j]);
    rep1(i,1,n)
        rep1(j,1,n){
            A[i][j] = 2*(a[i+1][j] - a[i][j]);
            A[i][n+1] += a[i+1][j]*a[i+1][j] - a[i][j]*a[i][j];
        }
    Gauss();
    printf("%.3f",A[1][n+1]);
    rep1(i,2,n) printf(" %.3f",A[i][n+1]);
}

View Code

View Code

 

 

相关文章