P1317 低洼地

题目描述

一组数,分别表示地平线的高度变化。高度值为整数,相邻高度用直线连接。找出并统计有多少个可能积水的低洼地?

如图:地高变化为 0 1 0 2 1 2 0 0 2 0

输入格式

两行,第一行n,表示有n个数。第2行连续n个数表示地平线高度变化的数据,保证首尾为0。(3<=n<=10000,0<=高度<=1000)

输出格式

一个数,可能积水低洼地的数目。

输入输出样例

输入 #1复制

10
0 1 0 2 1 2 0 0 2 0

输出 #1复制

3

 

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
using namespace std;

int main(int argc, char const *argv[])
{
	/* code */
	int n;
	
	cin >> n;
	vector<int> nums(n);
	for(int i = 0; i < n; i++)
	{
		cin >> nums[i];
	}
	int count = 0;
	int flag = 0;
	for(int i = 1; i < n-1; i++)
	{
		if(nums[i] < nums[i-1])
		{
			//找到一个下降沿
			flag = 1;

		}
		else if(nums[i] > nums[i-1])
		{
			if(flag == 1)
			{
				count++;
			}
			flag = 0;
		}
	}
	cout << count << endl;
	return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值