今年暑假不AC

这个题目,恩,又是让我很懵逼的一道,整体思路的话就是从时间长短排序,然后考虑衔接最短的,或者反过来也OK的,我又想用struct这个结构体,然而我只能给出思路和小部分细节,真是心塞塞 啊。

#include<cstdio>
#include<algorithm>
using namespace std;
struct tv
{int be,end;
}pro[105];
int cmp(const tv &a,const tv &b)
{
    if(a.be==b.be)
        return a.end<b.end;
    else
        return a.be<b.be;
}
int main()
{
    int n;
    while(scanf("%d",&n),n)
        {
            for(int i=0;i<n;i++)
                scanf("%d%d", &pro[i].be, &pro[i].end);
        sort(pro, pro + n, cmp);
            int bd,sum=1;
            bd=pro[0].end;
            for(int i=0;i<n;i++)
            {
                if(bd<=pro[i].be)
                {
                    sum++;
                    bd=pro[i].end;
                }
                else if(pro[i].end<bd)
                {
                    bd=pro[i].end;
                }
            }
            printf("%d\n",sum);
        }
        return 0;
}

  

posted @ 2016-07-22 19:07  阿银家的小贰  阅读(380)  评论(0编辑  收藏  举报