hdu 2037(最簡單的貪心演算法)
阿新 • • 發佈:2019-01-05
#include<iostream>
using namespace std;
struct tv
{
int s;
int e;
}a[105];
int cmp(const void*a,const void*b){
if (((tv*)a)->e == ((tv*)b)->e)
return ((tv*)a)->s - ((tv*)b)->s;
return ((tv*)a)->e - ((tv*)b)->e;
}
int n;
int main(){
while (cin>>n&&n)
{
for (int i = 0; i < n; i++){
cin >> a[i].s >> a[i].e;
}
qsort(a, n, sizeof(a[1]), cmp);
int num = 0, l = 0;
for (int i = 0; i < n; i++){
if (l <= a[i].s){
num++;
l = a[i].e;
}
}
cout << num << endl;
}
}