CCF CSP 202012-2 期末预测之最佳阈值
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct safety_index_info {
int safety_index, fail_num, pass_num;
safety_index_info(int y): safety_index(y), fail_num(0), pass_num(0){}
};
int main()
{
int m, threshold, max_precision = 0, precision;
vector<safety_index_info> sii_list;
cin >> m;
vector<vector<int> > students(m, vector<int>(2));
for (int i = 0; i < m; i++) cin >> students[i][0] >> students[i][1];
sort(students.begin(), students.end());
for (int i = 0; i < students.size(); i++) {
if (sii_list.empty() || sii_list.back().safety_index != students[i][0]) {
safety_index_info new_y_info(students[i][0]);
sii_list.push_back(new_y_info);
}
students[i][1] == 0 ? sii_list.back().fail_num++ : sii_list.back().pass_num++ , max_precision++;
}
threshold = sii_list[0].safety_index;
for (int i = 1; i < sii_list.size(); i++) {
precision = precision + sii_list[i - 1].fail_num - sii_list[i - 1].pass_num;
if (precision >= max_precision) {
threshold = sii_list[i].safety_index;
max_precision = precision;
}
}
cout << threshold << endl;
system("pause");
return 0;
}
统计每个安全指数对应的挂科学生数量和及格学生数量。对所有安全指数按照从小到大的顺序排序,以第 i 个安全指数作为阈值时的准确率 = 以第 i - 1 个安全指数作为阈值时的准确率 + 第 i - 1 个安全指数对应挂科学生的数量 - 第 i - 1 个安全指数对应及格学生的数量。