Oct0pus1 @ 2022-09-15 21:49:24
评测记录
#include<cstdio>
#define L 110
int n;
double a[L][L];
int main(){
scanf("%d",&n);
for(register int i=1;i<=n;i++)
for(register int j=1;j<=n+1;j++)scanf("%lf",&a[i][j]);
for(register int j=1;j<=n;j++){
if(!a[j][j]){
if(a[j][n+1])printf("-1");
else printf("0");
return 0;
}
for(register int i=1;i<=n;i++)
if(i!=j){
double tmp=a[i][j]/a[j][j];
for(register int k=1;k<=n+1;k++)a[i][k]-=tmp*a[j][k];
}
}
for(register int i=1;i<=n;i++)printf("x%d=%.2lf\n",i,a[i][n+1]/a[i][i]);
return 0;
}
by FFTotoro @ 2022-09-15 21:54:26
@Oct0pus1 可能是因为精度误差
by Oct0pus1 @ 2022-09-15 21:57:03
@zyc212303 细说
by VectorLi @ 2022-09-15 22:42:09
@Oct0pus1 !a[j][j]
可能需要改成 a[j][j] < EPS
?
by Oct0pus1 @ 2022-09-16 08:08:35
@VecTest 变成40分了 戳这里