【BZOJ 1013】【JSOI2008】球形空间产生器sphere 高斯消元基础题

最基础的高斯消元了,然而我把j打成i连WA连跪,考场上再犯这种错误就真的得滚粗了。

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
using namespace std;
double a[13][13],f[13];
int N;
inline double sqr(double x){return x*x;}
inline void swapp(double &d,double &b){double c=b;b=d;d=c;}
inline void gauss(){
for1(i,1,N-1){
int now=i;
for1(j,i+1,N) if (fabs(a[now][i])<fabs(a[j][i])) now=j;
for1(j,i,N+1) swapp(a[i][j],a[now][j]);
for1(j,i+1,N){
double chu=a[j][i]/a[i][i];
for1(k,i,N+1) a[j][k]-=chu*a[i][k];
}
}
for3(i,N,1){
for1(j,i+1,N) a[i][N+1]-=a[i][j]*a[j][N+1];
a[i][N+1]/=a[i][i];
}
}
int main(){
scanf("%d\n",&N);
memset(a,0,sizeof(a));memset(f,0,sizeof(f));
for1(i,1,N)scanf("%lf",&f[i]);
for1(i,1,N)for1(j,1,N){
double t; scanf("%lf",&t);
a[i][j]=2*(t-f[j]);
a[i][N+1]+=sqr(t)-sqr(f[j]);
}gauss();
for2(i,1,N) printf("%.3lf ",a[i][N+1]);
printf("%.3lf\n",a[N][N+1]);
return 0;
}

  然后就可以了

上一篇:Delphi StringReplace – 替换字符函数


下一篇:HTTP Status 404–/webDemo/hello