贪心的题目
按照持续时间去排序
时间相等则开始时间靠前的放在前面
放一个将对应的时间区间全部置1
注意判断的时候并不需要去判断区间端点的情况
看能不能再A一道,不行就回去开撸了 = =、
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
struct show
{
int st;
int et;
}h[1111];
bool cmp(show a,show b)
{
if(a.et-a.st==b.et-b.st)
return a.st<b.st;
return a.et-a.st<b.et-b.st;
}
int main()
{
int t,i,j;
int time[1111];
while(~scanf("%d",&t))
{ if(t==0)break;
for(i=0;i<t;i++)
scanf("%d%d",&h[i].st,&h[i].et);
sort(h,h+t,cmp);
int ans=0;
memset(time,0,sizeof(time));
int flag;
for(i=0;i<t;i++)
{
// if(h[i].et-h[i].st==1)
// if(time[h[i].st]==1&&time[h[i].et]==1)&&time[h[i].st-1]==1||time[h[i].et+1]==1)
// flag=1;break;
flag=0;
for(j=h[i].st;j<=h[i].et;j++)
{
if(j==h[i].st||j==h[i].et)
continue;
else if(time[j]==1)
{flag=1;break;}
else
continue;
}
if(flag==0)
{
for(j=h[i].st;j<=h[i].et;j++)
time[j]=1;
ans++;
}
}
// for(i=0;i<t;i++)
// printf("%d",time[i]);
// printf("\n");
printf("%d\n",ans);
}
return 0;
}