This commit is contained in:
Zengtudor 2024-10-04 19:07:21 +08:00
parent c07c6c63c7
commit 951a00aede
2 changed files with 62 additions and 1 deletions

View File

@ -31,4 +31,6 @@ add_executable(P1003 ${CMAKE_CURRENT_LIST_DIR}/P1003/P1003.cpp)
add_executable(P1311 ${CMAKE_CURRENT_LIST_DIR}/P1311/P1311.cpp)
add_executable(P4017 ${CMAKE_CURRENT_LIST_DIR}/P4017/P4017.cpp)
add_executable(P4017 ${CMAKE_CURRENT_LIST_DIR}/P4017/P4017.cpp)
add_executable(P2782 ${CMAKE_CURRENT_LIST_DIR}/P2782/P2782.cpp)

59
P2782/P2782.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <iostream>
#include <algorithm>
using std::cin,std::cout,std::sort,std::max;
constexpr int MAX_N {(int)2e5+5};
struct City{
int a,b;
bool operator<(const City &that)const noexcept{
return this->a<that.a;
}
} city[MAX_N];
int n, len[MAX_N],ans;
template<class T>
class ReadNumber{
char c;
T w,n;
public:
ReadNumber& operator>>(T &num)noexcept{
c=(char)0,w=1,n=0;
while(!isdigit(c)){
// if constexpr(!std::is_same_v<ull, T>){
// if(c=='-')w=-1;
// }
c = getchar();
}
while(isdigit(c)){
n = n*10 + (c-'0');
c = getchar();
}
num = w*n;
return *this;
}
};
ReadNumber<int> readint;
#define cin readint
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>city[i].a>>city[i].b;
len[i]=1;
}
sort(city,city+n);
for(int i=0;i<n;i++){
for(int j=i-1;j>=0;j--){
if(city[j].b<city[i].b && len[i]<len[j]+1){
len[i]=len[j]+1;
}
}
}
for(int i=0;i<n;i++){
// cout<<"i:"<<i<<" "<<"len:"<<len[i]<<'\n';
ans = max(ans,len[i]);
}
cout<<ans<<'\n';
}