CCF 202012-2 期末预测之最佳阈值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

//比较函数
bool cmp(vector<int> x,vector<int> y)
{
if(x[0] < y[0])//对于从小到大排序
return true;
if(x[0] == y[0])
if(x[1] > y[1])//当y相等的时候,把没有挂科的排在前面
return true;
return false;
}

int main()
{
int m;
cin >> m;
//创建二维数组储存数据,table[0]存储y,table[1]存储是否挂科
vector<vector<int>> table(m,vector<int>(2,0));
int max,// 存储可能性最大的阈值
before_gg = 0, //比当前阈值小的y中挂科的个数
after_w = 0; // 比当前阈值大于等于的y中没有挂科的个数
for(int i = 0;i < m;i++)
{
cin >> table[i][0] >> table[i][1];
if(table[i][1] == 1)
after_w++;// 统计所有没有挂科的人数
}
sort(table.begin(),table.end(),cmp); //排序
double chance,chance_m = 0;
for(int i = 0;i<m;i++)
{
//cout << table[i][0] << " " << table[i][1] << endl;
chance = (before_gg+after_w)/double(m); // 当前阈值的概率
if(chance >=chance_m)
{
chance_m = chance;
max = table[i][0];
}
if(table[i][1] == 0)
before_gg++; // 如果当前数据挂科,则对于下个数据,比他分数低的挂科人数+1
if(table[i][1] == 1)
after_w--; // 如果对于当前数据没有挂科,则对于下个数据,大于等于他的没有挂科人数-1
}
cout << max << endl;
return 0;
}

CCF 202012-2 期末预测之最佳阈值
http://blog.ulna520.com/2024/09/12/ccf-202012-2/
Veröffentlicht am
September 12, 2024
Urheberrechtshinweis