線段覆蓋(挖

我要轉到計算機機機發表於2020-11-30
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

struct oj {
	int b;
	int e;
};

bool cmp(oj a, oj b) {
	return a.e < b.e;
}

int main() {
	int n;
	scanf("%d", &n);
	struct oj a[n];
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i].b, &a[i].e);
	}
	sort(a, a + n, cmp);
	int s = 0;
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (a[i].b >= s) {
			s = a[i].e;
			count++;
		}
	}
	printf("%d", count);
	return 0;
}

相關文章