(非官方)本题数据生成器 && checker
查看原帖
(非官方)本题数据生成器 && checker
1096384
ctzm楼主2025/7/2 12:44

AI 写的数据生成器 && checker,方便各位调试。

程序默认 T=50,P=86T=50,P=86,输入文件写入当前目录下的 data.txt,输出文件写入当前目录下的 ans.txt,没有会自动创建。

#include <iostream>
#include <fstream>
#include <vector>
#include <random>
#include <cmath>
#include <algorithm>

using namespace std;

const int PLAYERS = 100;
const int QUESTIONS = 10000;

random_device rd;
mt19937 gen(rd());

// 生成[-3.0, 3.0]范围内的均匀分布随机数
uniform_real_distribution<> skill_dist(-3.0, 3.0);
uniform_real_distribution<> question_dist(-3.0, 3.0);

// sigmoid函数
double f(double x) {
    return 1.0 / (1.0 + exp(-x));
}

int main() {
    ofstream data_file("data.txt");
    ofstream ans_file("ans.txt");
    
    int T = 50;
    double P = 86.0; // 测试集2的参数
    
    // 写入输入文件头
    cout << T << endl;
    cout << P << endl;
    data_file << T << endl;
    data_file << P << endl;
    
    for (int case_num = 1; case_num <= T; ++case_num) {
        // 生成玩家技能值
        vector<double> S(PLAYERS);
        for (int i = 0; i < PLAYERS; ++i) {
            S[i] = skill_dist(gen);
        }
        
        // 生成问题难度值
        vector<double> Q(QUESTIONS);
        for (int j = 0; j < QUESTIONS; ++j) {
            Q[j] = question_dist(gen);
        }
        
        // 随机选择作弊者 (1-based)
        uniform_int_distribution<> cheat_dist(1, PLAYERS);
        int cheater = cheat_dist(gen);
        
        // 写入答案文件
        ans_file << "Case #" << case_num << ": " << cheater << endl;
        
        // 生成答题结果
        vector<string> results(PLAYERS, string(QUESTIONS, '0'));
        bernoulli_distribution coin(0.5);
        
        for (int i = 0; i < PLAYERS; ++i) {
            bool is_cheater = (i + 1 == cheater);
            
            for (int j = 0; j < QUESTIONS; ++j) {
                if (is_cheater && !coin(gen)) {
                    // 作弊者掷硬币反面,强制答对
                    results[i][j] = '1';
                } else {
                    // 正常答题
                    double prob = f(S[i] - Q[j]);
                    bernoulli_distribution answer(prob);
                    if (answer(gen)) {
                        results[i][j] = '1';
                    }
                }
            }
        }
        
        // 写入数据文件
        for (const auto& row : results) {
            cout << row << endl;
            data_file << row << endl;
        }
    }
    
    data_file.close();
    ans_file.close();
    return 0;
}

checker 从当前目录下 ans.txt(正确答案) 和 out.txt(你的输出)读入数据,并比对。TT 可以不是 5050,但需要两个文件有相同的输出个数。

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

using namespace std;

struct TestCase {
    int case_num;
    int answer;
};

vector<TestCase> read_answers(const string& filename) {
    vector<TestCase> cases;
    ifstream file(filename);
    string line;
    
    while (getline(file, line)) {
        if (line.find("Case #") == 0) {
            size_t colon_pos = line.find(':');
            int case_num = stoi(line.substr(6, colon_pos - 6));
            int answer = stoi(line.substr(colon_pos + 2));
            cases.push_back({case_num, answer});
        }
    }
    
    return cases;
}

int main() {
    vector<TestCase> out_cases = read_answers("out.txt");
    vector<TestCase> ans_cases = read_answers("ans.txt");
    
    if (out_cases.size() != ans_cases.size()) {
        cerr << "错误:两个文件的测试用例数量不同!" << endl;
        return 1;
    }
    
    int correct = 0;
    for (size_t i = 0; i < out_cases.size(); ++i) {
        if (out_cases[i].answer == ans_cases[i].answer) {
            correct++;
        } else {
            cout << "错误:测试用例 #" << out_cases[i].case_num 
                 << " 输出=" << out_cases[i].answer 
                 << " 正确=" << ans_cases[i].answer << endl;
        }
    }
    
    cout << "正确个数/总测试数: " << correct << "/" << out_cases.size() << endl;
    return 0;
}
2025/7/2 12:44
加载中...