这是一个我压力AI做出来的,模仿洛谷入门公开赛的得分按时间递减的checker.cpp,适用于全文比较(忽略行末空格及文末回车)的题(类似于洛谷不开spj的题)。
你可以自己修改更改区的内容,以适配你自己的比赛,但这个必须修改到和你的比赛实际情况一致,否则会出 bug。
此外,你需要手动更改计分方式为自定义,并保证计分规则为(测试点分数的加和)/(测试点数量) ,否则也会出错!
如果需要让这个实现 spj 功能,先自己写好 spj 程序,然后把main函数以外的东西原封不动的粘贴过来,把main函数里的东西粘贴到代码里的判题区即可。
注意:你写的spj要把quitf(_ac)的部分删去,只保留quitf(_wa)的部分,保证让spj检测到 WA 时直接退出,检测到 AC 则什么都不干。
需要自取吧qw
spj
#include "testlib.h"
#include <ctime>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <sstream>
using namespace std;
// =========================================================
// ************************* 更改区 *************************
// =========================================================
// 题目真实总满分(整道题所有测试点加起来的总分)
const double REAL_FULL_SCORE = 500.0;
// 洛谷题目设置中,单个测试点的分值(通常为 100,用于计算返回比例)
const double LUOGU_SCORE = 100.0;
// 开赛时间设置(北京时间)
const int START_YEAR = 2026; // 年
const int START_MONTH = 2; // 月
const int START_DAY = 11; // 日
const int START_HOUR = 8; // 时
const int START_MINUTE = 0; // 分
const int START_SECOND = 0; // 秒
// 总比赛时长设置
const int TOTAL_D = 0; // 天
const int TOTAL_H = 2; // 时
const int TOTAL_M = 0; // 分
const int TOTAL_S = 0; // 秒
// =========================================================
// *********************** 更改区结束 ***********************
// =========================================================
// 计算开赛时间戳(包含时区修正)
time_t get_start_time() {
struct tm t = {0};
t.tm_year = START_YEAR - 1900;
t.tm_mon = START_MONTH - 1;
t.tm_mday = START_DAY;
t.tm_hour = START_HOUR;
t.tm_min = START_MINUTE;
t.tm_sec = START_SECOND;
t.tm_isdst = -1;
// 北京时间(UTC+8) 转 UTC时间戳,需减去 8 小时
return mktime(&t) - (8 * 3600);
}
// 读取输入流,去除行末空格和文末空行
std::vector<std::string> read_and_trim(InStream& in) {
std::vector<std::string> lines;
while (!in.seekEof()) {
std::string line = in.readLine();
while (!line.empty() && isspace((unsigned char)line.back())) {
line.pop_back();
}
lines.push_back(line);
}
while (!lines.empty() && lines.back().empty()) {
lines.pop_back();
}
return lines;
}
int main(int argc, char* argv[]) {
registerTestlibCmd(argc, argv);
// =========================================================
// ************************* 判题区 *************************
// =========================================================
std::vector<std::string> user_lines = read_and_trim(ouf);
std::vector<std::string> ans_lines = read_and_trim(ans);
if (user_lines.size() != ans_lines.size()) {
quitf(_wa, "Wrong Answer");
}
for (size_t i = 0; i < ans_lines.size(); i++) {
if (user_lines[i] != ans_lines[i]) {
quitf(_wa, "Wrong Answer");
}
}
// =========================================================
// *********************** 判题区结束 ***********************
// =========================================================
// 1. 计算当前测试点的真实得分
time_t now = time(NULL);
time_t start_time = get_start_time();
double diff_seconds = difftime(now, start_time);
double t_hours = diff_seconds / (TOTAL_D * 86400.0 + TOTAL_H * 3600.0 + TOTAL_M * 60.0 + TOTAL_S * 1.0);
if (t_hours < 0) t_hours = 0;
// 单个测试点的满分 = 总分 / 测试点数量
double case_full_score = REAL_FULL_SCORE;
// 根据时间衰减公式计算本测试点实际得分
double p = (1.3 / (t_hours + 1.3)) * case_full_score;
// 2. 计算返回给 OJ 的比例 (实际得分 / 卷面分)
double ret = p / LUOGU_SCORE;
// 3. 返回结果
stringstream msg;
msg << fixed << setprecision(5);
msg << "Time: " << t_hours << "h. Case Score: " << p;
quitp(ret, "%s", msg.str().c_str());
return 0;
}示例计分脚本,适用于测试点数为20的情况,时间等规则与加和方式一致
@total_score = (@score1 + @score2 + @score3 + @score4 + @score5 + @score6 + @score7 + @score8 + @score9 + @score10 + @score11 + @score12 + @score13 + @score14 + @score15 + @score16 + @score17 + @score18 + @score19 + @score20) / 20;
@final_time = @time1 + @time2 + @time3 + @time4 + @time5 + @time6 + @time7 + @time8 + @time9 + @time10 + @time11 + @time12 + @time13 + @time14 + @time15 + @time16 + @time17 + @time18 + @time19 + @time20;
@final_memory = @memory1;
if @memory2 > @final_memory; then @final_memory = @memory2; fi
if @memory3 > @final_memory; then @final_memory = @memory3; fi
if @memory4 > @final_memory; then @final_memory = @memory4; fi
if @memory5 > @final_memory; then @final_memory = @memory5; fi
if @memory6 > @final_memory; then @final_memory = @memory6; fi
if @memory7 > @final_memory; then @final_memory = @memory7; fi
if @memory8 > @final_memory; then @final_memory = @memory8; fi
if @memory9 > @final_memory; then @final_memory = @memory9; fi
if @memory10 > @final_memory; then @final_memory = @memory10; fi
if @memory11 > @final_memory; then @final_memory = @memory11; fi
if @memory12 > @final_memory; then @final_memory = @memory12; fi
if @memory13 > @final_memory; then @final_memory = @memory13; fi
if @memory14 > @final_memory; then @final_memory = @memory14; fi
if @memory15 > @final_memory; then @final_memory = @memory15; fi
if @memory16 > @final_memory; then @final_memory = @memory16; fi
if @memory17 > @final_memory; then @final_memory = @memory17; fi
if @memory18 > @final_memory; then @final_memory = @memory18; fi
if @memory19 > @final_memory; then @final_memory = @memory19; fi
if @memory20 > @final_memory; then @final_memory = @memory20; fi
if @status1 == AC and @status2 == AC and @status3 == AC and @status4 == AC and @status5 == AC and @status6 == AC and @status7 == AC and @status8 == AC and @status9 == AC and @status10 == AC and @status11 == AC and @status12 == AC and @status13 == AC and @status14 == AC and @status15 == AC and @status16 == AC and @status17 == AC and @status18 == AC and @status19 == AC and @status20 == AC; then
@final_status = AC;
else
@final_status = UNAC;
fi