已添加 spj

P2455 [SDOI2006] 线性方程组

离散小波变换° @ 2024-02-26 14:17:59

原题保留到小数点后两位并在比较时采用全文比较,可能会导致无限的精度问题(例如本贴第二个 Hack 数据)。因此特添加 spj,对于有唯一解的情况,标准答案 X=[x_1,x_2,\cdots,x_n] 及用户输出的解 X'=[x_1',x_2',\cdots,x_n'] 只需要满足:

\max_{1\le i\le n}\left\{\dfrac{|x_i-x_i'|}{\max(|x_i|,1.0)}\right\}\le 0.01

即判定为正确。

完整 spj:

#include "testlib.h"
using namespace std;

string type(string x){
    if(x == "-1")
        return "no solution";
    if(x == "0")
        return "infinity solution";
    return "unique solution";
}

int main(int argc, char* argv[]){
    registerTestlibCmd(argc, argv);

    int n = inf.readInt();

    string oline = ouf.readLine();
    string aline = ans.readLine();

    string atype = type(aline);
    string otype = type(oline);

    if(atype != otype){
        quitf(_wa, "The equations have %s, but your output is %s.", atype.c_str(), otype.c_str());
    } else {
        if(atype != "unique solution")
            quitf(_ok, "Good job.");
        else {
            for(int i = 1;i <= n;++ i){
                string str_ans = aline.substr(aline.find('=') + 1);
                string str_out = oline.substr(oline.find('=') + 1);

                long double val_ans = atof(str_ans.c_str());
                long double val_out = atof(str_out.c_str());

                if(abs(val_ans - val_out) / max(abs(val_ans), 1.0L) <= 0.01 + 1e-9){
                    // ok
                } else {
                    quitf(_wa, "x%d = %s, but read %s.", i, str_ans.c_str(), str_out.c_str());
                }

                if(i != n){
                    oline = ouf.readLine();
                    aline = ans.readLine();
                }
            }
        }
        quitf(_ok, "Good job.");
    }

    return 0;
}

by WydnksqhbD @ 2024-02-26 14:20:44

qp


by Jerry_heng @ 2024-02-26 14:30:27

qp


by _int123_ @ 2024-02-26 14:34:13

qp


by zhjx2023 @ 2024-02-26 14:35:40

qp


by PDP233 @ 2024-02-26 14:39:29

qp


by OneSheeep @ 2024-02-26 14:53:27

qp


by 2345A @ 2024-02-26 15:01:06

qp


by 羊叫兽同学 @ 2024-02-26 15:49:45

qp


by Ian_NIE @ 2024-02-26 15:51:58

qp


by yu1128 @ 2024-02-26 16:18:55

qp


| 下一页