HDOJ2037

/*节目越早结束,就能看越多节目*/
#include
#include
#include
#include
using namespace std;


#define M 1005
int num[M] = { 0 };


struct aa
{
int s, e;
}a[M];


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


int main()
{
int n;
while (cin >> n, n)
{
int sum = 1,j=0;
for (int i = 0; i < n; i++) cin >> a[i].s >> a[i].e;
sort(a, a + n, cmp);
for (int i = 1; i < n; i++)
{
if (a[i].s >= a[j].e)
{
sum++;
j = i;
}
}
cout << sum << endl;
}
}

你可能感兴趣的:(贪心)