题目描述
一组数,分别表示地平线的高度变化。高度值为整数,相邻高度用直线连接。找出并统计有多少个可能积水的低洼地?
如图:地高变化为 0 1 0 2 1 2 0 0 2 0
输入输出格式
输入格式:
两行,第一行n,表示有n个数。第2行连续n个数表示地平线高度变化的数据,保证首尾为0。(3<=n<=10000,0<=高度<=1000)
输出格式:
一个数,可能积水低洼地的数目。
输入输出样例
输入样例#1:
100 1 0 2 1 2 0 0 2 0
输出样例#1:
3 数组模拟lyq大坑比
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #define LL long long 8 #define lb(x) ((x)&(-x)) 9 using namespace std;10 const int MAXN=1000001;11 inline int read()12 {13 char c=getchar();int x=0,f=1;14 while(c<'0'||c>'9') { if(c=='-') f=-1;c=getchar();}15 while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();return x*f;16 }17 int n;18 int a[MAXN];19 int main()20 {21 n=read();22 for(int i=1;i<=n;i++)23 a[i]=read();24 int nowhigh=a[2],ans=0;25 for(int i=2;i<=n;i++)26 {27 if(a[i]>nowhigh) nowhigh=a[i];28 if(a[i+1] a[i+1]) ans++,nowhigh=a[i+2],i=i+1;29 }30 printf("%d",ans);31 return 0;32 }33 34 /*35 1136 37 10 9 8 8 8 7 8 2 1 1 238 */