123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include <iostream>
- #include<algorithm>
- #include <vector>
- using namespace std;
- struct Pair {
- int start;
- int end;
- };
- bool compare(Pair a, Pair b) {
- return a.end < b.end;
- }
- int maxPart(vector<Pair> pairs) {
- if (pairs.size() < 1) {
- return 0;
- }
- sort(pairs.begin(), pairs.end(), compare);
- int result = 1;
- int start = pairs[0].end;
- for (int i = 1; i < pairs.size(); i++) {
- if (pairs[i].start >= start) {
- start = pairs[i].end;
- result++;
- }
- }
- return result;
- }
- int main() {
- int n;
- while (cin >> n) {
- if (n < 1) {
- continue;
- }
- vector<Pair> pairs;
- for (int i = 0; i < n; i++) {
- Pair pair;
- cin >> pair.start >> pair.end;
- pairs.push_back(pair);
- }
- cout << maxPart(pairs) << endl;
- }
- return 0;
- }
|