题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2037
其实题目跟会场会议安排是一样的,只是上一个节目的结束时间可以与下一个节目开始的时间相同,一次水过,如果不懂的可以去看NYOJ 14 会场会议安排。
代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
struct hy
{
int begin;
int end;
}w[1001];
bool comp(hy x,hy y)
{
if(x.end<y.end) return true;
return false;
}
int main()
{
int n,i,p,count;
while(~scanf("%d",&n)&&n)
{
for(i=0;i<n;i++)
{
scanf("%d %d",&w[i].begin,&w[i].end);
}
sort(w,w+n,comp);
p=0;count=1;
for(i=1;i<n;i++)
{
if(w[i].begin>=w[p].end)
{
count++;
p=i;
}
}
printf("%d\n",count);
}
return 0;
}