标签:std ret cst line const algo == can turn
高斯-约当消元(这里以JSOI2008球形空间产生器)
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define db double
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
inline int in()
{
int k=0;char ch=gt;
while(ch<'-')ch=gt;
while(ch>'-')k=k*10+ch-'0',ch=gt;
return k;
}
db a[15][15];
int p[15],o[15];
const db eps=1e-3;
int main()
{
int n=in()+1;
for(int i=1;i<=n;++i)
{
for(int j=1;j<n;++j)
scanf("%lf",a[i]+j),a[i][n+1]+=a[i][j]*a[i][j],a[i][j]*=2;
a[i][n]=1;
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)if(!o[j]&&fabs(a[j][i])>eps){p[i]=j;break;}
double t=a[p[i]][i];o[p[i]]=1;
for(int j=1;j<=n+1;++j)a[p[i]][j]/=t;
for(int k=1;k<=n;++k)
{
if(p[i]==k)continue;
t=a[k][i];
for(int j=1;j<=n+1;++j)a[k][j],a[k][j]-=a[p[i]][j]*t;
}
}
for(int i=1;i<n;++i)printf("%.3lf ",a[p[i]][n+1]);puts("");
return 0;
}
标签:std ret cst line const algo == can turn
原文地址:https://www.cnblogs.com/cx233666/p/9737473.html