果然如Miracle学长所说。。。调了一天。。。qwq。。还是过不了线下的Hack
upd after 40min:刚刚过了
就是多了一个判无解的操作。。。
当系数都为0,且常数项不为0时,即为无解。
当找到*元时,不能跳过这一行。。。否则会被Hack,见洛谷讨论
#include<cstdio>
#include<iostream>
#include<cmath>
#define R register int
using namespace std;
const double eps=1E-;
inline int g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
}
long double a[][];
int n,m,k;
inline bool ck0(double x) {return x<eps&&x>-eps;}
inline void Gauss() {
for(R i=,pos=;i<=n&&pos<=n;++i) { R p;
for(p=pos;p<=n&&ck0(a[p][i]);++p) ;
if(p==n+) continue;
if(pos!=p) for(R j=;j<=n+;++j) swap(a[pos][j],a[p][j]);
for(R j=pos+;j<=n;++j) if(!ck0(a[j][i])){
register long double t=a[j][i]/a[pos][i];
for(R k=;k<=n+;++k) a[j][k]-=a[pos][k]*t;
} ++pos;
} register bool flg1=false,flg2=false;
for(R i=;i<=n;++i) { R j=;
while(ck0(a[i][j])&&j<=n+) ++j;
if(j==n+) flg1=true;
if(j>n+) flg2=true;
} if(flg1) {putchar('-'),putchar(''); return ;}
if(flg2) {putchar(''); return ;}
for(R i=n;i>=;--i) {
for(R j=n;j>=i+;--j) a[i][n+]-=a[i][j]*a[j][n+];
a[i][n+]/=a[i][i];
} for(R i=;i<=n;++i) if(ck0(a[i][n+])) printf("x%d=0\n",i); else printf("x%d=%.2Lf\n",i,a[i][n+]);
}
signed main() {
n=g(); for(R i=;i<=n;++i) for(R j=;j<=n+;++j) a[i][j]=g(); Gauss(); //while(1);
}
2019.05.13