题解 | #活动安排#
活动安排
https://www.nowcoder.com/practice/16d971e9e42e4f3b9b1e2b8794796a43
#include <iostream> #include <utility> #include<vector> #include<algorithm> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> arr(n); for(int i = 0; i < n; i ++){ int a, b; cin >> a >> b; arr[i] = {a, b}; } sort(arr.begin(), arr.end(),[](pair<int, int> &x, pair<int, int> &y){ return x.second < y.second; } ); int start = -1e9, end = -1e9; int res = 0; for(pair<int, int> v : arr){ if(end <= v.first){ end = v.second; res ++; } } cout << res << endl; return 0; } // 64 位输出请用 printf("%lld")