离散小波变换° @ 2024-02-26 14:17:59
原题保留到小数点后两位并在比较时采用全文比较,可能会导致无限的精度问题(例如本贴第二个 Hack 数据)。因此特添加 spj,对于有唯一解的情况,标准答案
即判定为正确。
完整 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 kevinZ99 @ 2024-02-26 16:59:01
qp
by xiaoke2021 @ 2024-02-26 21:21:58
qp
by I_like_play_eggy @ 2024-08-10 06:54:48
qp