标签:for ons namespace fill i+1 ++ lower 重写 qsort
重写排序方法
#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;
}
标签:for ons namespace fill i+1 ++ lower 重写 qsort
原文地址:http://www.cnblogs.com/unknownname/p/7792642.html