这俩道题目的代码基本和pku 3636一样的
主要的区别就是第二个元素排序时同样也是递增排序,因为第一个元素相同时,第二个元素按递增顺序可以全部加入,不用重新再增加桶
所以后面的一个判断条件也要将等号去掉
pku1065
#include<iostream>
#include<algorithm>
using namespace std;
struct Node
{
int h,w;
bool operator<(Node a){
if(a.w==w)
return h<a.h;
return w<a.w;
}
}ele[5010];
int a[5010];
int main()
{
int cas,n;
cin>>cas;
while(cas--)
{
cin>>n;
for(int i=0;i<n;i++)
cin>>ele[i].w>>ele[i].h;
sort(ele,ele+n);
int q=0;
for(int i=0;i<n;i++)
{
int l=0,r=q;
while(l<r)
{
int m=(r+l)/2;
if(a[m]>ele[i].h)
l=m+1;
else r=m;
}
a[l]=ele[i].h;//a[]保存每个桶的边界值
q+=l==q;//假如,没有找到,就新加一个桶。
}
cout<<q<<endl;
}
return 0;
}
pku 1548
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
friend bool operator<(const node &a,const node &b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
}ele[24*24];
int f[25];
int main()
{
int a,b,n=0;
while(cin>>a>>b&&(a!=-1||b!=-1))
{
if(a==0&&b==0)
{
sort(ele,ele+n);
int l,r,q=0;
for(int i=0;i<n;i++)
{
l=0;r=q;
while(l<r)
{
int m=(l+r)/2;
if(f[m]>ele[i].y)
l=m+1;
else r=m;
}
f[l]=ele[i].y;
q+=l==q;
}
cout<<q<<endl;
n=0;continue;
}
ele[n].x=a;ele[n].y=b;
n++;
}
return 0;
}