codeforces 597B Restaurant

题目链接:http://codeforces.com/contest/597/problem/B

题目分类:贪心

题目分析:经典的看节目问题(挑战程序设计page 40)

代码

#include<bits/stdc++.h>

using namespace std;

struct P
{
    int st,en;
}order[500005];

int cmp(P X,P Y)
{
    return X.en<Y.en;
}

int main()
{
    int n;
    scanf("%d",&n);
    memset(order,0,sizeof(order));
    for(int i=1;i<=n;i++)
    {
        cin>>order[i].st>>order[i].en;
    }

    sort(order+1,order+n+1,cmp);

    int ans=0,t=0;
    for(int i=1;i<=n;i++)
    {
        if(order[i].st>t)
        {
            ans++;
            t=order[i].en;
        }

    }
    printf("%d\n",ans);
    return 0;
}

 

你可能感兴趣的:(codeforces 597B Restaurant)