songyuan888 @ 2022-08-19 13:10:21
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
double c[110][110];
bool is(double a)
{
return a<1e-6;
}
int gs()
{
int e,r,i,t,j;
for(e=0,r=0;e<n;e++)
{
t=r;
for(i=r;i<n;i++)
{
if(c[i][e]>c[t][e])
t=i;
}
if(is(fabs(c[t][e])))
continue;
for(i=e;i<=n;i++)
swap(c[t][i],c[r][i]);
for(i=n;i>=e;i--)
c[r][i]=c[r][i]/c[r][e];
for(i=r+1;i<n;i++)
{
if(is(fabs(c[i][e])))
continue;
for(j=n;j>=e;j--)
c[i][j]=c[i][j]-c[r][j]*c[i][e];
}
r++;
}
if(r<n)
{
for(i=r;i<n;i++)
if(is(fabs(c[i][n])))
return 2;
return 1;
}
for(i=n-1;i>=0;i--)
for(j=i+1;j<n;j++)
c[i][n]=c[i][n]-c[i][j]*c[j][n];
return 0;
}
int main()
{
int t,i,j;
cin>>n;
for(i=0;i<n;i++)
for(j=0;j<=n;j++)
cin>>c[i][j];
t=gs();
if(t==1)
cout<<"-1"<<endl;
else if(t==2)
cout<<"0"<<endl;
else
{
for(i=0;i<n;i++)
cout<<"x"<<i+1<<"="<<fixed<<setprecision(2)<<c[i][n]<<endl;
}
return 0;
}
RT,不知道怎么就WA了#8,越调分越低QWQ
by Binary_Lee @ 2022-08-19 13:49:50
我WA #8#9