zoukankan      html  css  js  c++  java
  • 结构体排序

    重写排序方法

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<vector>
    #include<iostream>
    using namespace std;

    const int N=1e6+5;
    const int INF=0x7fffffff;

    int dp[N];
    int n;

    struct Road
    {
        int B;
        int E;
    }road[N];

    int cmp( const void *a , const void *b )
    {
        struct Road *c = (Road *)a;
        struct Road *d = (Road *)b;
        return c->B > d->B;
    }

    int solve()
    {
        fill(dp,dp+n,INF);
        /*
        Road t;
        int Min;
        for(int i=0;i<=n-2;i++)
        {
            Min=i;
            for(int j=i+1;j<n;j++)
            {
                if(road[Min].B>road[j].B)
                {
                    Min=j;
                }
            }
            if(Min!=i)
            {
                t=road[i];
                road[i]=road[Min];
                road[Min]=t;
            }
        }
        */
        qsort(road,n,sizeof(road[0]),cmp);
        /*
        for(int i=0;i<n;i++)
            printf("%d ",road[i].B);
            */
        for(int i=0;i<n;i++)
        {
            *lower_bound(dp,dp+n,road[i].E)=road[i].E;
        }
        int ans=lower_bound(dp,dp+n,INF)-dp;
        return ans;
    }

    int main()
    {
        int cas=0;
        while(~scanf("%d",&n))
        {
            for(int i=0;i<n;i++)
            {
                cin>>road[i].B>>road[i].E;
            }
            int res=solve();
            if(res==1)
                printf("Case %d: My king, at most %d road can be built. ",++cas,res);
            else
                printf("Case %d: My king, at most %d roads can be built. ",++cas,res);
        }
        return 0;
    }

  • 相关阅读:
    转:Jmeter之Bean shell使用(一)
    转:Curl详解
    转:MIME(Multipurpose Internet Mail Extensions)类型
    转:Tomcat配置
    转:windows 7系统安装与配置Tomcat服务器环境
    转:Apache POI Tutorial
    转:Busy Developers' Guide to HSSF and XSSF Features
    转:Java实现几种常见排序方法
    转:JAVA强制类型转换
    转:Java的各种类型转换汇总
  • 原文地址:https://www.cnblogs.com/unknownname/p/7792642.html
Copyright © 2011-2022 走看看