正题
题目链接:https://www.luogu.org/problem/P3389
题目大意
给出一个nnn元一次方程组,求解。
解题思路
模板,有什么好说的吗
codecodecode
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=110;
int n;
double b[N],c[N][N];
int main()
{scanf("%d",&n);for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)scanf("%lf",&c[i][j]);scanf("%lf",&b[i]);}for(int i=1;i<=n;i++){int z=i;for(int j=i+1;j<=n;j++){if(fabs(c[j][i])>fabs(c[z][i]))z=j;}for(int j=1;j<=n;j++)swap(c[i][j],c[z][j]);swap(b[i],b[z]);if(!c[i][i]){printf("No Solution\n");return 0;}for(int j=1;j<=n;j++){if(i==j) continue;double rate=c[j][i]/c[i][i];for(int k=i;k<=n;k++)c[j][k]-=c[i][k]*rate;b[j]-=b[i]*rate; }}for(int i=1;i<=n;i++)printf("%.2lf\n",b[i]/c[i][i]);
}