当前位置:网站首页>LCP 11. Statistics of expected number
LCP 11. Statistics of expected number
2022-07-26 20:41:00 【Mr Gao】
LCP 11. The expected number of statistics
The annual spring move of an Internet company began , Altogether n Interviewers were selected . Every interviewer will submit a resume , The company will generate an estimated ability value based on the resume data provided , The higher the value, the more likely it is to pass the interview .
Small A And small B Responsible for reviewing interviewers , They have resumes of all interviewees , And they will browse according to the interviewer's ability value from large to small . Because the resume has been disrupted in advance , Resumes with the same ability value appear in the order of medium possibility from their full ranking . Now given n The ability value of an interviewer scores, set up X For little A And small B The number of resumes that appear in the same position in the browsing order , seek X The expectations of the .
Tips : The expected calculation formula of discrete nonnegative random variables is 1. In the subject , because X The values for 0 To n Between , The expected calculation formula can be 2.
Example 1:
Input :scores = [1,2,3]
Output :3
explain : Because the ability values of interviewers are different from each other , Small A And small B The browsing order must be the same .X The expectation is 3 .
Example 2:
Input :scores = [1,1]
Output :1
explain : Set the number of two interviewers as 0, 1. Because their ability values are 1, Small A And small B The browsing order of is from full order [[0,1],[1,0]] Take one moderately possible . If small A And small B The browsing order is [0,1] perhaps [1,0] , So the number of resumes in the same position is 2 , It is 0 . therefore X The expectation is (2+0+2+0) * 1/4 = 1
Example 3:
Input :scores = [1,1,2]
Output :2
Limit :
The solution code is as follows :
void quick(int *a,int low,int high){
if(low<high){
int l=low,h=high,p=a[low];
while(low<high){
while(low<high&&a[high]>=p){
high--;
}
a[low]=a[high];
while(low<high&&a[low]<=p){
low++;
}
a[high]=a[low];
}
a[low]=p;
quick(a,l,low-1);
quick(a,low+1,h);
}
}
int expectNumber(int* scores, int scoresSize){
int count=0;
quick(scores,0,scoresSize-1);
int base=scores[0];
int i;
// printf("%d ",scores[0]);
for(i=1;i<scoresSize;i++){
if(scores[i]!=base){
count++;
// printf("%d %d ",scores[i],count);
base=scores[i];
}
}
return count+1;
}
边栏推荐
- NVIDIA Canvas 初体验~
- Do employees have to compensate the company for losses when they resign? The 34 year old captain resigned and was claimed 10.66 million yuan by the company
- 使用百度飞桨 EasyDL 完成垃圾分类
- nmap安装和使用
- Auto.js 旋转图标
- Face recognition and fingerprint recognition are weak? Pentagon develops long-distance heartbeat recognition
- arpspoof 安装和使用
- Task 2 kaggle diabetes detection
- Quick start to connection pooling
- The UK and Germany have successively launched 5g commercial services, and Huawei has become a behind the scenes hero
猜你喜欢
随机推荐
tkinter使用wpf控件
Game partner topic: breederdao and ultiverse have established a new metauniverse
EtherCAT synchronization mode
[wechat applet] zero basics | applet syntax
Kotlin - 协程构建器 CoroutineBuilder
How to obtain Cu block partition information in HM and draw with MATLAB
The lawyer team of the US Department of justice asked the judge to refuse to accept Huawei's lawsuit
Solve attributeerror: module 'win32com.gen_ py. 00020813-0000-0000-C000-000000000046x0x1x9‘ has no attribu
How to praise others gracefully? Try these methods
arpspoof 安装和使用
Solve the horizontal segmentation of iBGP and BGP routing principles
BGP routing black hole and anti ring
BUU刷题记-网鼎杯专栏2
Leetcode-300 longest increasing subsequence
单核A7玩转人脸识别,恩智浦“跨界处理器”又玩出新花样!
一层节点训练5个坐标的超简单神经网络代码
BUU刷题记1
smoothscroll-polyfill插件的用法
数字化工厂有哪些关键技术
聊天软件项目开发2
![[wechat applet] zero basics | applet syntax](/img/3d/fb999fde6f61af62337464ea8e32bd.png)







