精華區beta Marginalman 關於我們 聯絡資訊
3025. 圖畫出來就清楚ㄌ 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; } }; ----- Sent from JPTT on my iPad -- 很姆的咪 姆之咪 http://i.imgur.com/5sw7QOj.jpg -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.99.218 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1756832927.A.3AB.html