今日学习记录
1. 3025. 人员站位的方案数 I
关键词:模拟 排序
问题分析:
- 就是站格子
核心思路
- 先排序在一个个比较,记录最低下限,上限遇不到不用管
**最终代码:
int numberOfPairs(vector<vector<int>>& points) {
sort(points.begin(),points.end(),[](const auto&a,const auto&b){
if(a[0]==b[0]) return a[1]>b[1];
else return a[0]<b[0];
});
int n = points.size();
int ans = 0;
for(int i = 0;i<n-1;i++){
int a = points[i][1];
int bt = -1;
for(int j = i+1;j<n;j++){
int b = points[j][1];
if(b>a) continue;
if(b>bt) ans++,bt = b;
}
}
return ans;
}学到的点:
- 简单