zoukankan      html  css  js  c++  java
  • hrbust 2080链表 【贪心】

    仔细看题想想就是个贪心题,两个sort就可以解决了

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<time.h>
    #include<iostream>
    #include<ctype.h>
    #include<map>
    #include<set>
    #include<string>
    #include<vector>
    #include<algorithm>
    #include<stdlib.h>
    #include<queue>
    #include<stack>
    using namespace std;
    struct DD
    {
        int a,b;
    
    }A[100005];
    int cmp(DD x,DD y)
    {
        if(x.a==y.a)
            return x.b<y.b;
        return x.a<y.a;
    }
    int cmp2(DD x,DD y)
    {
        if(x.b==y.b)
            return x.a<y.a;
        return x.b<y.b;
    }
    int main()
    {
        int n,i,j;
        while(~scanf("%d",&n))
        {
            for(i=0;i<n;i++)
                scanf("%d%d",&A[i].a,&A[i].b);
            sort(A,A+n,cmp);
            int n1=1;
            int w=A[0].a;
            int e=A[0].b;
            for(i=1;i<n;i++)
            {
                if(A[i].a>e)
                {
                    e=A[i].b;
                    n1++;
                }
            }
            sort(A,A+n,cmp2);
            int n2=1;
            int qq=A[0].b;
            for(i=1;i<n;i++)
            {
                if(A[i].a>qq)
                {
                    n2++;
                    qq=A[i].b;
                }
            }
            printf("%d
    ",max(n1,n2));
        }
    }
  • 相关阅读:
    makefile简单例子
    js归并排序
    js插入排序
    js堆排序
    js选择排序
    js冒泡算法以及优化
    使用go语言判断不同数据类型
    go使用接口案例排序
    go接口使用案例晓demo
    go面向对象-继承
  • 原文地址:https://www.cnblogs.com/nr1999/p/8997252.html