update
This commit is contained in:
parent
951a00aede
commit
0661f341bd
@ -33,4 +33,8 @@ add_executable(P1311 ${CMAKE_CURRENT_LIST_DIR}/P1311/P1311.cpp)
|
||||
|
||||
add_executable(P4017 ${CMAKE_CURRENT_LIST_DIR}/P4017/P4017.cpp)
|
||||
|
||||
add_executable(P2782 ${CMAKE_CURRENT_LIST_DIR}/P2782/P2782.cpp)
|
||||
add_executable(P2782 ${CMAKE_CURRENT_LIST_DIR}/P2782/P2782.cpp)
|
||||
|
||||
add_executable(P1091 ${CMAKE_CURRENT_LIST_DIR}/P1091/P1091.cpp)
|
||||
|
||||
add_executable(P1020 ${CMAKE_CURRENT_LIST_DIR}/P1020/P1020.cpp)
|
16
P1020/P1020.cpp
Normal file
16
P1020/P1020.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin, std::cout, std::iostream;
|
||||
|
||||
constexpr size_t MAX_N {(size_t)5e4+5};
|
||||
int n, arr[MAX_N], len[MAX_N], ans1, ans2;
|
||||
|
||||
int main(){
|
||||
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
|
||||
|
||||
cin>>n;
|
||||
for(size_t i=0;i<n;i++){
|
||||
cin>>arr[i];
|
||||
}
|
||||
|
||||
}
|
35
P1091/P1091.cpp
Normal file
35
P1091/P1091.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
using std::cin,std::cout,std::max,std::iostream;
|
||||
|
||||
constexpr size_t MAX_N {100+5};
|
||||
int n, arr[MAX_N], go_up[MAX_N], go_down[MAX_N], ans;
|
||||
|
||||
int main(){
|
||||
iostream::sync_with_stdio(false),cin.tie(0),cout.tie(0);
|
||||
|
||||
cin>>n;
|
||||
for(int i=0;i<n;i++){
|
||||
cin>>arr[i];
|
||||
go_up[i]=1,go_down[i]=1;
|
||||
}
|
||||
for(int i=0;i<n;i++){//j < i
|
||||
for(int j=i-1;j>=0;j--){
|
||||
if(arr[j]<arr[i] && go_up[i]<go_up[j]+1){
|
||||
go_up[i] = go_up[j]+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=n-1;i>=0;i--){//i < j
|
||||
for(int j=i+1;j<n;j++){
|
||||
if(arr[j]<arr[i] && go_down[i]<go_down[j]+1){
|
||||
go_down[i] = go_down[j] + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0;i<n;i++){
|
||||
ans = max(ans,go_down[i]+go_up[i]-1);
|
||||
}
|
||||
cout<<n-ans<<'\n';
|
||||
}
|
Loading…
Reference in New Issue
Block a user