/* 区间不相交问题 */ #include <algorithm> using namespace std;
const int MaxN = 10; struct interval { int x, y; //开区间左右端点 } I[MaxN];
bool cmp(interval a, interval b) { if (a.x != b.x) return a.x > b.x; //先按照左端点从大到小的顺序排序 return a.y < b.y; // 如果左端点相同, 则按照右端点从小到大的顺序排序 }
int main() { int n; while (scanf_s("%d", &n), n!=0){ for (int i = 0; i < n; ++i) { scanf_s("%d%d", &I[i].x, &I[i].y); } sort(I, I + n, cmp); int ans = 1, lastX = I[0].x; for (int i = 1; i < n; ++i) { if (I[i].y <= lastX) { lastX = I[i].x; ans++; } } printf("%d",ans); } return 0; }