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
",ans);
    return 0;
}
anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
原文地址:https://www.cnblogs.com/gaoss/p/4973331.html