hdu 2037 今年暑假不AC(贪心)

#include <stdio.h>
#include <algorithm>

using namespace
std; 

 

#define MAXN 101

struct
TNode
{

int
beg;
int
end;
};

TNode time[MAXN]; 

inline bool myCmp(const TNode &t1, const TNode &t2)
{

return
t1.end < t2.end;
}

int main()
{

#ifndef ONLINE_JUDGE
freopen("indata.txt", "r", stdin);
#endif

int
n;
while
(scanf("%d", &n), n)
{

int
i;
for
(i = 0; i < n; i++)
{

scanf("%d %d", &time[i].beg, &time[i].end);
}

sort(time, time + n, myCmp);

int cnt = 1, j = 0;
for
(i = 1; i < n; i++)
{

if
(time[i].beg >= time[j].end)
{

cnt++;
j = i;
}
}

printf("%d\n", cnt);
}

return
0;
}


posted @ 2010-10-31 15:04  菜到不得鸟  阅读(114)  评论(0)    收藏  举报