interestingLSY @ 2018-02-05 19:24:05
#include <bits/stdc++.h>
#define INF (0x3f3f3f3f)
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))
#define Pb push_back
#define Mp make_pair
#define ll long long
#define _tp template
#define _tyn typename
#define All(x) x.begin(),x.end()
#define Ms(_data) memset(_data,0,sizeof(_data))
#define Msn(_data,_num) memset(_data,_num,sizeof(_data))
using namespace std;
#define Mymax(a,b) if(a<b) a = b;
#define Mymin(a,b) if(a>b) a = b;
#define il inline
#define rg register
#define For(i,j) for( rg int (i) = 1 ; (i) <= (j) ; (i)++ )
#define For0(i,j) for( rg int (i) = 0 ; (i) < (j) ; (i)++ )
#define Forx(i,j,k) for( rg int (i) = (j) ; (i) <= (k) ; (i)++ )
#define fOR(i,j) for( rg int (i) = (j) ; (i) >= 1 ; (i)-- )
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
#define MAXN 120
#define ld double
#define EPS 1e-10
il void Noans(){
printf("-1\n");
exit(0);
while(1);
}
il void Infans(){
printf("0\n");
exit(0);
while(1);
}
struct Equ{
ld a[MAXN];
};
int n;
ld ans[MAXN];
Equ equ[MAXN];
bool Exist( ld x ){
return fabs(x) >= EPS;
}
bool operator<( Equ e1 , Equ e2 ){
For(i,n)
if( abs(e1.a[i]) != abs(e2.a[i]) )
return abs(e1.a[i]) > abs(e2.a[i]);
return 1;
}
void Gauss( int pos ){
if( pos == n ){
if( Exist(equ[n].a[n]) ) ans[n] = equ[n].a[n+1] / equ[n].a[n];
else{
if( Exist(equ[n].a[n+1]) ) Noans();
else Infans();
}
return;
}
sort(equ+pos,equ+1+n);
Forx(j,pos+1,n){
if( !equ[j].a[pos] ) continue;
ld mul = -equ[j].a[pos] / equ[pos].a[pos];
Forx(k,pos,n+1)
equ[j].a[k] += equ[pos].a[k] * mul;
}
Gauss(pos+1);
Forx(i,pos+1,n)
equ[pos].a[n+1] -= equ[pos].a[i] * ans[i];
if( !Exist(equ[pos].a[pos]) ){
if( Exist(equ[pos].a[n+1]) ) Noans();
else Infans();
}
ans[pos] = equ[pos].a[n+1] / equ[pos].a[pos];
if( ans[pos] == -0 ) ans[pos] = 0;
}
int main(){
scanf("%d",&n);
For(i,n){
For(j,n+1)
scanf("%lf",&equ[i].a[j]);
}
Gauss(1);
For(i,n)
printf("x%d=%.2lf\n",i,ans[i]);
return 0;
}
#1
AC
0ms/2152KB
#2
AC
0ms/2117KB
#3
AC
0ms/2156KB
#4
AC
0ms/2082KB
#5
AC
0ms/2253KB
#6
AC
0ms/2160KB
#7
AC
0ms/2160KB
#8
AC
0ms/2226KB
#9
AC
0ms/2128KB
#10
WA
by interestingLSY @ 2018-02-05 19:29:38
On line 1 column 1, read 0, expected -1. 得分0