反正我没考试看看代码居然才2、30行就不编了甩上来看看
来第一题题目就不发了自己去找
#include<cstdio>
using namespace std;
int const N = 100010;
int n;
int h[N];
int tot=0;
int main(){
freopen("block.in","r",stdin);
freopen("block.out","w",stdout);
scanf("%d",&n);
scanf("%d",&h[1]);
tot=h[1];
for(int i=2;i<=n;i++){
scanf("%d",&h[i]);
if(h[i]>h[i-1]) tot+=h[i]-h[i-1];
}
printf("%d",tot);
return 0;
}
第二题
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const N = 100010;
int n;
int h[N];
int ans=0;
int main(){
freopen("flower.in","r",stdin);
freopen("flower.out","w",stdout);
scanf("%d",&n);
int flag=-1;
for(int i=1;i<=n;i++){
scanf("%d",&h[i]);
if(i!=1&&h[i]>h[i-1]&&flag!=0){//flag 为 0 表示上升
ans++;
flag=0;
}
if(i!=1&&h[i]<h[i-1]&&flag!=1){
ans++;
flag=1;
}
}
printf("%d",ans+1);
return 0;
}