楼主:
sixB (6B)
2025-09-03 01:08:433025.
图画出来就清楚ㄌ
sort过之后画boundary
奇怪为啥我分两次sort会歪掉:3
好吧好吧
class Solution {
public:
int numberOfPairs(vector<vector<int>>& p) {
// wa to sd
// p[y][x] sort by x
int n = p.size();
//sort(p.begin(), p.end(), [](auto& a, auto& b){return a[0] > b[0];});
sort(p.begin(), p.end(), [](auto& a, auto& b){
if(a[1] < b[1]) return true;
else if(a[1] == b[1] and a[0] > b[0]) return true;
return false;
});
int res = 0;
for(int i = 0; i < n; i++){
int y = p[i][0], x = p[i][1];
//cout << y << " " << x << '\n';
int bottom = -1;
for(int j = i+1; j < n and bottom < y; j++){
int cy = p[j][0], cx = p[j][1];
if(cy > y) continue;
if(bottom < cy){
res++;
bottom = cy;
}
}
}
return res;
}
};