1 条题解
-
0
C++ :
#include<cstdio> const int N=100010; int h[N]={0}; int main() { int n,i,a,b,c,ans=2; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&h[i]); for(i=2;i<n;i++) {if(h[i-1]<h[i]&&h[i]>h[i+1])ans++; if(h[i-1]>h[i]&&h[i]<h[i+1])ans++; if(h[i]==h[i+1])h[i]=h[i-1];} printf("%d",ans); return 0; }
Pascal :
const maxhigh:longint=1000001; var h:array[1..100001]of longint;i,n,ans:longint; begin readln(n); for i:=1 to n do read(h[i]); readln; close(input); h[n+1]:=maxhigh; i:=1; if h[i]>h[i+1] then begin while h[i]>h[i+1] do inc(i);ans:=2 end else ans:=1; while i<n do begin while (h[i]<h[i+1])or(h[i]=h[i+1]) do inc(i); inc(ans); if i<n then begin while (h[i]>h[i+1])or(h[i]=h[i+1]) do inc(i); inc(ans) end end; writeln(ans) end.
- 1
信息
- ID
- 319
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者