贪心--区间调度问题
原创
©著作权归作者所有:来自51CTO博客作者wx596330ff6d68f的原创作品,请联系作者获取转载授权,否则将追究法律责任
题目:书P40-41
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX_LEN = 100005;
int n;
int s[MAX_LEN], t[MAX_LEN];
struct Work {
int Start;
int End;
}_work[MAX_LEN];
bool Cmp(const Work& w1, const Work& w2) {
return w1.End < w2.End;
}
int main() {
int Result = 0; int tmp = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &_work[i].Start);
}
for (int i = 0; i < n; i++) {
scanf("%d", &_work[i].End);
}
sort(_work, _work + n, Cmp);
for (int i = 0; i < n; i++) {
if (tmp <= _work[i].Start) {
tmp = _work[i].End;
Result++;
}
}
printf("%d", Result);
system("pause");
return 0;
}