WA#2求助
查看原帖
WA#2求助
286770
Andrewzdm楼主2021/9/30 18:59

WA#2

显示Too short on line 1,为什么啊……

//P2455
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = 50;
const double eps = 1e-5;
double a[maxn][maxn];
int n;

int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n + 1; ++j)
            cin >> a[i][j];
    int cur = 1, pos;
    for(int i = 1; i <= n; ++i)
    {
        pos = cur;
        for(int j = cur + 1; j <= n; ++j)
            if(fabs(a[j][i]) > fabs(a[pos][i]))
                pos = j;
        if(fabs(a[pos][i]) < eps)
            continue;
        for(int j = 1; j <= n + 1; ++j)
            swap(a[cur][j], a[pos][j]);
        for(int j = 1; j <= n; ++j)
        {
            if(j == cur) continue;
            double tmp = a[j][i] / a[cur][i];
            a[j][i] = 0;
            for(int k = i + 1; k <= n + 1; ++k)
                a[j][k] -= a[cur][k] * tmp;
        }
        ++cur;
    }
    if(cur <= n)
    {
        bool flag = true;
        for(int i = cur; i <= n; ++i)
            if(fabs(a[i][n + 1]) > eps)
            {
                flag = false;
                break;
            }
        puts(flag ? "0" : "-1");
    }
    else for(int i = 1; i <= n; ++i)
        printf("x%d=%.2lf\n", i, a[i][n + 1] / a[i][i]);
    return 0;
}

猜测可能是因为本该输出解的情况输出了 001-1, 但是为什么会这样呢qwq

2021/9/30 18:59
加载中...