标签:
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2037
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 47163 Accepted Submission(s):
25332
#include<algorithm>
#include<cstdio>
using namespace std;
struct Ti
{
int s,e;
}ti[105];
int cmp(Ti a, Ti b)
{
if( a.e == b.e ) return a.s > b.s;
else return a.e < b.e ;
}
int main()
{
int t,i,j,sum;
while( scanf("%d",&t) && t )//t=0时结束输入
{
sum=1;
for(i=0; i<t; i++)
{
scanf("%d%d", &ti[i].s, &ti[i].e);
}
sort(ti, ti+t, cmp);
j=ti[0].e;
for(i=1; i<t; i++)
{
if( j <= ti[i].s )
{
sum++;
j=ti[i].e;
}
}
printf("%d\n",sum);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/123tang/p/5699503.html