时间: 2020-11-23|62次围观|0 条评论

http://acm.hdu.edu.cn/showproblem.php?pid=2037(简单贪心-----活动安排)

#include<iostream>
#include<algorithm>
using namespace std;

struct Node
{
    int l, r;
}a[105];

bool Cmp(Node x, Node y)
{
    if(x.r!=y.r) return x.r<y.r;
    else return x.l>y.r;
}

int main()
{
    int n;
    while(scanf("%d", &n)!=EOF, n)
    {
        for(int i=0; i<n; i++)
        scanf("%d%d", &a[i].l, &a[i].r);
        sort(a, a+n, Cmp);
        int ans = 1, flag = a[0].r;
        for(int i=1; i<n; i++)
        {
            if(a[i].l>=flag)
            {
                ans++;
                flag=a[i].r;
            }
        }
        printf("%d\n", ans);
    }    
    return 0;
}

 

转载于:https://www.cnblogs.com/acm1314/p/4628852.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/96718657

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《hdu2037———–贪心, 活动安排问题
   

还没有人抢沙发呢~