提交时间:2024-07-17 11:12:19

运行 ID: 156397

#include<iostream> #include<algorithm> using namespace std; struct stu{ int start, end; bool is_in; void input(){ cin >> start >> end; if(start > end) swap(start, end); is_in = false; } bool operator == (const stu & o) const{ return start <= o.end || end <= o.start; } bool operator != (const stu & o) const{ return !(start <= o.end || end <= o.start); } bool operator < (const stu & o) const{ return end <= o.end; } }; stu ary[40010]; int main(){ int n; cin >> n; for(int i = 0; i < n; i++){ ary[i].input(); } sort(ary, ary + n); int cnt = 0; int now = 0; for(int i = 0; i < n; i++){ if(ary[i].start > now){ cnt++; now = ary[i].end; } } cout << n - cnt; return 0; }