您的位置:首页 > 其它

hdu 1025 Constructing Roads In JGShining's Kingdom

2016-03-31 21:47 260 查看
http://blog.csdn.net/sdjzping/article/details/8762508

最长上升子序列

#include<iostream>
#include<algorithm>
#define maxn 500010
using namespace std;
int n,casee=1;
struct stu
{
int x,y;
};
stu mapp[maxn];
bool cmp(stu x,stu y)
{
return x.x<y.x;
}
void solve()
{
int f[maxn];
int k=0;
f[k++]=mapp[0].y;
for(int i=1;i<n;i++)
{
if(mapp[i].y>=f[k-1]) f[k++]=mapp[i].y;
else
{
int pos=upper_bound(f,f+k,mapp[i].y)-f;
f[pos]=mapp[i].y;
}
}
cout<<"Case "<<casee++<<":"<<endl;
if(k==1)
{
cout<<"My king, at most 1 road can be built."<<endl;
}
else
{
cout<<"My king, at most "<<k<<" roads can be built."<<endl;
}
cout<<endl;
}
void input()
{
for(int i=0;i<n;i++) cin>>mapp[i].x>>mapp[i].y;
sort(mapp,mapp+n,cmp);
solve();
}
int main()
{
cin.sync_with_stdio(false);
while(cin>>n)
{
input();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: