当前位置:网站首页>[CSP]202012-2期末预测之最佳阈值
[CSP]202012-2期末预测之最佳阈值
2022-06-12 17:29:00 【yuri5151】
题目
- 样例1:
输入
6
0 0
1 0
1 1
3 1
5 1
7 1
输出
3
- 样例2
输入
8
5 1
5 0
5 0
2 1
3 0
4 0
100000000 1
1 0
输出
100000000
题解
原来顺着题意走,先用set存储各个阈值,再在各个阈值下计算预测正确的个数
这样就有了双层循环,导致超时
可以观察到,随着阈值的增加,通过(re=1)的值是在不断减小的,未通过则增加,其是有一定规律的
若按上面直接逐一统计,会出现许多重复计算
则可以尝试先算出整体通过、未通过的数量,阈值增加则增或减响应数量来达到统计正确率的目的
详细讲解在注释
m = int(input())
p,n = 0,0 # 先找出所有通过与不通过的数
result,theta = [],[]
for i in range(m):
y,score = map(int,input().split())
if score: p+=1 # 统计所有通过的
else: n+=1 # 统计所有未通过的
result.append([y,score])
result = sorted(result)
p1=p # p1记录在当前分数线下通过的数量
j = -1 # 分数线数组theta的游标
for i in range(m): # 先正着计算,后面比她大的都是通过的,每遇到一个通过的就少一个
if i==0: # 第一个值先直接放入(第一个遇到的,作阈值)
theta.append([result[i][0],p1]) # 第一个元素,直接放入
j+=1 # theta游标+1
elif result[i][0] != result[i-1][0]: # 出现新阈值(分数不一样才作为新分割线)
theta.append([result[i][0],p1]) # 以该元素为起点,后面是比他高的,则分类正确的数量为p1
j+=1
if result[i][1]: p1-=1 # 每路过一个通过的值,就会少一个
n1 = n
# 再从后向前,看分数线前没通过的值,也是判断正确的
for i in range(m-1,-1,-1):
''' 注意: 因为>=分数线都是通过,所以上面处理通过时先存入再减去 而分数线下,<就是不通过,不能等于,所以要先处理 '''
if not result[i][1]: n1 -= 1 # 走过一个为通过的,就少一个
if result[i][0] != result[i-1][0]: # 遇到新阈值
theta[j][1]+=n1 # 小于阈值的,未通过的值为n1,也是正确的
j-=1 # theta前进一个(下一个阈值)
print(sorted(theta,key = (lambda x:x[1]))[-1][0]) # 按正确率排序(都一样再按数值升序)
# 取最后一个数据输出
边栏推荐
- String s = null ; String s = new String();String s =““ ;String s ;有什么区别?
- 使用GCC的PGO(Profile-guided Optimization)优化整个系统
- Hangzhou AI developer meetup registration opens!
- 文章名字
- Hangzhou AI developer meetup registration opens!
- How to win the "Olympic Games" in retail technology for jd.com, the learning tyrant of the "regular examination"?
- Enterprise internal online training system source code
- First acquaintance with go language
- [BSP video tutorial] stm32h7 video tutorial Issue 8: the last issue of the MDK theme, the new generation of debugging technologies event recorder and RTT, and using stm32cubemx to generate project tem
- Implementation of asynchronous query of Flink dimension table and troubleshooting
猜你喜欢
多种Qt的开发方式,你选择哪种?
如何查看、修改和删除SSH
Learn the mitmproxy packet capturing tool from scratch
1723. minimum time to complete all work
Gerrit+2 triggers Jenkins task
有趣的 LD_PRELOAD
Volcano engine held a video cloud technology force summit and released a new experience oriented video cloud product matrix
Application case of smart micro 32-bit MCU for server application cooling control
How to use the official documents of pytorch and torchvision
Quick start sweep crawler framework
随机推荐
Tidb Hackathon 2021 - pcloud: conduct icloud pcloud team interview on the database
ShardingJDBC 分库分表详解
Introduction to several common functions of fiddler packet capturing (stop packet capturing, clear session window contents, filter requests, decode, set breakpoints...)
Volcano engine held a video cloud technology force summit and released a new experience oriented video cloud product matrix
[BSP video tutorial] stm32h7 video tutorial Issue 8: the last issue of the MDK theme, the new generation of debugging technologies event recorder and RTT, and using stm32cubemx to generate project tem
ftrace
R语言使用epiDisplay包的tableStack函数基于分组变量生成统计分析表(包含描述性统计分析、假设检验、不同数据使用不同的统计量和假设检验方法)、自定义配置是否显示统计检验内容
Cloud development kunkun chicken music box wechat applet source code
How to win the "Olympic Games" in retail technology for jd.com, the learning tyrant of the "regular examination"?
(5) Outputs and outputs
(三)Golang - 数据类型
两位新晋Committer的“升级攻略”
Crazy temporary products: super low price, big scuffle and new hope
1723. minimum time to complete all work
Where is it safer to open an account for thermal coal futures? How much is the thermal coal futures deposit?
selenium元素定位
错误记录:IllegalStateException: Optional int parameter ‘xxxx‘ is
WinForm, crystal report making
性能优化之编译优化
(4) Golang operator