当前位置:网站首页>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();
}
};
边栏推荐
- 【Matlab印刷字符识别】OCR印刷字母+数字识别【含源码 1861期】
- saltstack部署zabbix状态文件编写
- Promise details
- [MATLAB image encryption and decryption] chaotic sequence image encryption and decryption (including correlation test) [including GUI source code 1862]
- [并发进阶]——线程池总结
- The realization of online Fox game server room configuration battle engagement customization function
- VTK-vtkPlane和vtkCutter使用
- 教育专家王中泽老师:家庭教育重在自己成长
- Detailed explanation of mutationobserver
- First day of database
猜你喜欢

Leetcode hot topic 100 topic 6-10 solution

【LeetCode】-- 17.电话号码的字母组合

latex 各种箭头/带文字标号的箭头/可变长箭头

A highly controversial issue

常用问题排查工具和分析神器,值得收藏

网狐游戏服务器房间配置向导服务定制功能页实现

Analysis of key points and difficulties of ES6 promise source code

Flutter Container组件

Duality-Gated Mutual Condition Network for RGBT Tracking

.NET C#基础(6):命名空间 - 有名字的作用域
随机推荐
Graph Attention Tracking
Records how cookies are carried in cross domain requests
1266_ Implementation analysis of FreeRTOS scheduler startup code
SQL query. Only the column name is displayed but not the data
saltstack部署lnmp
Leetcode-9.Palindrome Numbber
洛谷P1091合唱队形(最长上升子序列)
双周投融报:资本抢滩元宇宙游戏
The meaning and research significance of mathematical methodology
Shuttle inside and outside margins
JS implementation of graphic merging and sorting process [source code attached]
无心剑汉英双语诗001.《爱》
Required reading 1: the larger the pattern, the better they know how to speak
June training (day 11) - matrix
Explain the difference between void 0 and undefined
迅为干货 |瑞芯微RK3568开发板TFTP&NFS烧写(上)
并发工具类
Esp32 learning notes (49) - esp-wifi-mesh interface use
生物序列智能分析平台blog(1)
[probability theory and mathematical statistics] Dr. monkey's notes p41-44 statistics related topics, determination of three distributions, properties, statistics subject to normal distribution in gen