CSP202012-2 期末预测之最佳阈值

时间:2021-08-30
本文章向大家介绍CSP202012-2 期末预测之最佳阈值,主要包括CSP202012-2 期末预测之最佳阈值使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<algorithm>
 4 using namespace std;
 5 const int m=100000;
 6 struct node 
 7 {
 8     int data, result, chance;
 9 }student[m];
10 bool cmp(node a, node b)
11 {
12     if (a.data == b.data)
13     {
14         return a.result > b.result;
15     }
16     else
17     {
18         return a.data < b.data;
19     }
20 }
21 int main(void)
22 {
23     int n;
24     cin >> n;
25     for (int i = 0; i < n; i++)
26     {
27         cin >> student[i].data >> student[i].result;
28         student[i].chance = 0;
29     }
30     sort(student, student + n, cmp);
31     //找出最大阈值准确率
32     for (int i = 0; i < n - 1; i++)
33     {
34         if (student[i].result == 0)
35         {
36             student[n - 1].chance++;
37         }
38     }
39     if (student[n - 1].result == 1)
40     {
41         student[n - 1].chance++;
42     }
43     //获取前一个阈值的准确率
44     for (int i = n - 1; i >= 0; i--)
45     {
46         student[i].chance = student[i + 1].chance;
47         if (student[i].result == 1)
48         {
49             student[i].chance++;
50         }
51         else
52         {
53             student[i].chance--;
54         }
55     }
56     //去重
57     for (int i = 0; i < n - 1; i++)
58     {
59         if (student[i].data == student[i + 1].data)
60         {
61             student[i + 1].chance = student[i].chance;
62         }
63     }
64     //找到阈值
65     int t = student[0].chance;
66     int max;
67     for (int i = 0; i < n; i++)
68     {
69         if (t <= student[i].chance)
70         {
71             t = student[i].chance;
72             max = student[i].data;
73         }
74     }
75     
76         cout << max;
77     return 0;
78 }    

参考:https://blog.csdn.net/weixin_45693289/article/details/115877445?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.control&spm=1001.2101.3001.4242

原文地址:https://www.cnblogs.com/qingdaodaozhu/p/15207303.html