当前位置:网站首页>Interview question 17.08 Circus tower
Interview question 17.08 Circus tower
2022-06-11 07:02:00 【Not coriander】
Interview questions 17.08. Circus tower
There's a circus that's designing a lot of shows , One should stand on the shoulder of another . For practical and aesthetic reasons , The person above is shorter and lighter than the person below . We know the height and weight of everyone in the Circus , Please write code to calculate how many people can be stacked at most .
Example :
Input :height = [65,70,56,75,60,68] weight = [100,150,90,190,95,110]
Output :6
explain : Count from top to bottom , At most, a man can fold 6 layer :(56,90), (60,95), (65,100), (68,110), (70,150), (75,190)
Tips :
height.length == weight.length <= 10000
class Solution {
public:
int bestSeqAtIndex(vector<int>& height, vector<int>& weight) {
int n=height.size();
vector<pair<int,int> >p;
for(int i=0;i<n;i++){
p.push_back(pair<int,int>(height[i],weight[i]));
}
sort(p.begin(),p.end(),[](const pair<int,int>&a,const pair<int,int>&b){
if(a.first==b.first){
return a.second>b.second;
}
else{
return a.first<b.first;
}
});
vector<int>v;
for(int i=0;i<n;i++){
//cout<<p[i].first<<" "<<p[i].second<<endl;
int len=v.size();
if(len==0||p[i].second>v[len-1]){
v.push_back(p[i].second);
}
int l,r;
l=0;
r=len-1;
while(l<=r){
int mid=(l+r)/2;
if(v[mid]>=p[i].second){
r=mid-1;
}
else{
l=mid+1;
}
}
if(l<len){
v[l]=p[i].second;
}
// cout<<l<<" "<<len<<endl;
}
return v.size();
}
};
边栏推荐
- Aircraft war from scratch (II) simple development
- Cv2.rectangle() picture frame
- Illustrate the principle of one-way linked list and the method of JS to realize linked list [with source code]
- byte和bit的区别
- Aircraft battle from scratch (III) flight between player aircraft and enemy aircraft
- 【Matlab印刷字符识别】OCR印刷字母+数字识别【含源码 1861期】
- Shutter restraint container assembly
- Required reading 1: the larger the pattern, the better they know how to speak
- [matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]
- This comprehensive understanding
猜你喜欢

Check whether the filing information of the medical representative is correct

无心剑汉英双语诗001.《爱》

Analysis of key points and difficulties of ES6 promise source code

Object. Specific implementation and difference between create() and new

News web page display
![[deploy private warehouse based on harbor] 3 deploy harbor](/img/cd/be68a430e86b4b23ad93b42a338f00.jpg)
[deploy private warehouse based on harbor] 3 deploy harbor
![[matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]](/img/fd/53776b550390752282cd8797193436.png)
[matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]

About the designer of qtcreator the solution to the problem that qtdesigner can't pull and hold controls normally

matplotlib的cmap

资深OpenStacker - 彭博、Vexxhost升级为OpenInfra基金会黄金成员
随机推荐
Quick sorting of graphic array [with source code]
Common troubleshooting tools and analysis artifacts are worth collecting
Comparison of DOM tags of wechat applet development (native and uniapp)
Shuttle inside and outside margins
Notice on organizing the application for the first edition of Ningbo key software in 2022
First day of database
AtomicInteger原子操作类
Practice: how to reasonably design functions to solve practical problems in software development (II) -- improving reusability
JS implementation of Hill sort of graphic insertion sort [with source code]
[matlab WSN communication] a_ Star improved leach multi hop transmission protocol [including source code phase 487]
Duality-Gated Mutual Condition Network for RGBT Tracking
微信小程序开发(原生和uniapp)DOM标签对比介绍
.NET C#基础(6):命名空间 - 有名字的作用域
AppClips&Tips(持续更新)
Matplotlib,设置坐标刻度大小,字体/设置图例大小及字体/设置纵横坐标名称及字体及大小
saltstack部署zabbix状态文件编写
网狐游戏服务器房间配置向导服务定制功能页实现
Flutter 约束容器组件
The difference between TCP and UDP
[deploy private warehouse based on harbor] 3 deploy harbor