当前位置:网站首页>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();
}
};
边栏推荐
- Starting from scratch (V) realize bullet positioning and animation
- Grayscale publishing through ingress
- Zabbix 监控主机是否在线
- Luogu p1091 chorus formation (longest ascending subsequence)
- 双周投融报:资本抢滩元宇宙游戏
- Detailed explanation of mutationobserver
- Flat design, blog website (VIII) code source code
- sql查询问题,只显示列名 不显示数据
- Illustration of JS implementation from insertion sort to binary insertion sort [with source code]
- This comprehensive understanding
猜你喜欢

Transformer Tracking
![[并发进阶]——线程池总结](/img/69/dc8146dafc30f8a8efa012b67aa05c.png)
[并发进阶]——线程池总结
![Illustration of JS implementation from insertion sort to binary insertion sort [with source code]](/img/e5/1956af15712ac3e89302d7dd73f403.jpg)
Illustration of JS implementation from insertion sort to binary insertion sort [with source code]

Starting from scratch (IV) enemy aircraft flying out of the border disappear automatically

Shutter restraint container assembly

Common troubleshooting tools and analysis artifacts are worth collecting

matplotlib的cmap

Leetcode-141. Linked List Cycle

品牌定位个性六种形态及结论的重大意义

河南高考VS天津高考(2008年-2021年)
随机推荐
Stack -- one of two common linear structures of linear structure
Illustration of JS implementation from insertion sort to binary insertion sort [with source code]
This comprehensive understanding
Leetcode-104. Maximum Depth of Binary Tree
Group arrays by a specified size
Promise details
A promise with bare hands
Explain the difference between void 0 and undefined
Xunwei dry goods | Ruixin micro rk3568 development board TFTP & NFS writing (Part 1)
品牌定位个性六种形态及结论的重大意义
Pytest自动化测试-简易入门教程(01)
Do you use typescript or anyscript
[MATLAB image encryption and decryption] chaotic sequence image encryption and decryption (including correlation test) [including GUI source code 1862]
常用问题排查工具和分析神器,值得收藏
Graph Attention Tracking
无心剑汉英双语诗001.《爱》
Flutter 内外边距
Listen to the left width of the browser to calculate the distance
Analysis of key points and difficulties of ES6 promise source code
sql查询问题,只显示列名 不显示数据