结构体排序

重写排序方法

#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:\nMy king, at most %d road can be built.\n",++cas,res);
        else
            printf("Case %d:\nMy king, at most %d roads can be built.\n",++cas,res);
    }
    return 0;
}

转载于:https://www.cnblogs.com/unknownname/p/7792642.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值