完成“导弹拦截”

This commit is contained in:
Hmtsai 2024-07-09 15:04:20 +08:00
parent ce649523f8
commit 46bed7f87b
2 changed files with 26 additions and 0 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"C_Cpp.default.compilerPath": "c:\\Users\\Administrator\\Downloads\\llvm-mingw-20240619-ucrt-x86_64\\llvm-mingw-20240619-ucrt-x86_64\\bin\\aarch64-w64-mingw32-clang++.exe"
}

23
mooc/导弹拦截.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <iostream>
int main(){
int a[1001],fall[1001],rise[1001],n=0,most=0,least=0;
while(std::cin>>a[++n]){
for(int i=0;i<=n;i++){
fall[i]=1;
rise[i]=1;
for(int j=0;j<i;j++){
if(a[i]<=a[j]){
fall[i]=std::max(fall[i],fall[i+1]);
}
if(a[i]>a[j]){
rise[i]=std::max(rise[i],rise[i+1]);
}
}
most=std::max(most,fall[i]);
least=std::max(least,rise[i]);
}
}
return 0;
}