重写排序方法
#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;
}