WA on #2 精度求助

P2455 [SDOI2006] 线性方程组

滑稽的小宫 @ 2021-05-12 15:36:50

#include<iostream>
#include<cstdio>
#define ll long long
#define db double
#define eps 1e-7
#define N 110
int n,m;
bool noans=false,uncertain=false;
db ans[N];
bool equal(db a,db b){
    return a-b<eps&&b-a<eps;
}class line{
    public:
    db a[N];
    line operator *(db x)const{
        line ans=(*this);
        for(int i=1;i<=n+1;i++)ans.a[i]*=x;
        return ans;
    }line operator +(line A)const{
        line ans=(*this);
        for(int i=1;i<=n+1;i++)ans.a[i]+=A.a[i];
        return ans;
    }bool iszero(){
        for(int i=1;i<=n;i++)if(!equal(a[i],0))return false;
        return true;
    }
}P;
class basis{
    public:
    line b[N];
    void insert(line A){
        int pos=-1;
        for(int i=1;i<=n;i++){
            if(!equal(A.a[i],0)){
                if(pos==-1&&equal(b[i].a[i],0))pos=i;
                else if(!equal(b[i].a[i],0))A=b[i]*(-A.a[i]/b[i].a[i])+A;
            }
        }if(A.iszero()&&!equal(A.a[n+1],0))noans=true;
        if(pos==-1)return;
        b[pos]=A;
        for(int i=1;i<=n;i++)if(i!=pos)b[i]=A*(-b[i].a[pos]/A.a[pos])+b[i];
        return;
    }bool check(){
        for(int i=1;i<=n;i++)if(b[i].iszero())return false;
        return true;
    }
    void sendback(){
        ans[n+1]=-1;
        for(int i=n;i>=1;i--){
            db sum=0;
            for(int j=i;j<=n+1;j++)sum+=ans[j]*b[i].a[j];
            ans[i]=-sum/b[i].a[i];
        }
    }
}B;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n+1;j++){
            scanf("%lf",&P.a[j]);
        }B.insert(P);
    }/*for(int i=1;i<=n;i++){
        for(int j=1;j<=n+1;j++)printf("%.2lf ",B.b[i].a[j]);
        printf("\n");
    }*/
    if(noans)printf("-1");
    else if(!B.check())printf("0");
    else for(int i=1;i<=n;i++)printf("x%d=%.2lf\n",i,(B.b[i].a[n+1]/B.b[i].a[i]+eps));
    return 0;
}

第二个点怎么调eps都过不去,显示第21行第8个数应该是5,我的答案是6

(似乎不是printf四舍五入的问题)


|