已添加 spj
查看原帖
已添加 spj
68344
离散小波变换°3rd eye楼主2024/2/26 14:17

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

max⁡1≤i≤n{∣xi−xi′∣max⁡(∣xi∣,1.0)}≤0.01\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;
}
2024/2/26 14:17
加载中...